apt update
apt install mysql-server
ps -ef | grep mysql
lsof -i:3306
需在控制面板->点击程序->启用或关闭windows功能->找到telnet客户端并勾选
终端输入telnet 8.130.127.54 3306
vim /etc/mysql/mysql.conf.d/mysqld.cnf
改为bind-address = 0.0.0.0保存退出
systemctl restart mysql
终端输入 telnet 8.130.127.54 3306 弹出遗失对主机的连接则正确
mysql -u root -p
show databases;
use mysql;
show tables;
select * from user;
desc user;
select Host,User from user;
update user set Host='%' where User='root';
select Host,User from user;后提示为
“+-----------+------------------+
| Host | User |
+-----------+------------------+
| % | root |
| localhost | debian-sys-maint |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
5 rows in set (0.00 sec)则成功”
FLUSH PRIVILEGES;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123';
FLUSH PRIVILEGES;
exit
mysql -u root -p 之后需输入密码123
进入成功则服务器安装配置成功
打开idea
新建一个文件名为db-demo 选择Maven文件
点击窗口右侧的database点击左上角的加号选择Data Source->Mysql
在Database处输入eshop
Host位置为阿里云服务器的ip
User名字为root
在下面设置一个简单的密码
然后点击Test Connection提示为绿色对号则成功(此处有可能得下个插件点击Download即可)
进入阿里云服务器输入 create database eshop;创建一个数据库
SHOW DATABASES;
表格内出现刚才新建数据库的名称即可、
之后返回idea刚才创建的页面点ok即可
右键点击db-demo新建一个文件名字随便起后面扩展名必须为.sql
在新建文件里面输入 show databases ; 之后点击左上角的运行选择eshop@********* 之后选择consel之后会在终端处弹出数据表格
在 .sql文件内输入
create table books (id int auto_increment primary key ,title varchar(100),author varchar(100),price float,year int);
//( insert into books(title, author, price, year) values ('Java','John',100,2010);
insert into books(title, author, price, year) values ('C++','Smith',200,2011);
insert into books(title, author, price, year) values ('Pathon','David',300,2012);
insert into books(title, author, price, year) values ('Ruby','Tom',400,2013);
insert into books (title, author, price, year) values ('Perl','Jerry',500,2014);
select * from books;//)
show tables ;
先选中括号外的代码运行 在选中括号内的代码运行