mysql远程连接

1,问题截图

2,确认防火墙已关闭

1)直接关闭防火墙

[root@localhost ~]# firewall-cmd --state
running
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# firewall-cmd --state
not running

2)开放对应端口3306

[root@localhost ~]# firewall-cmd --permanent --add-port=3306/tcp
success
[root@localhost ~]# systemctl restart firewalld

[root@localhost ~]# netstat -an|grep 3306
tcp6 0 0 :::3306 :::* LISTEN

3,更改对应字段

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> update user set host = ’%’ where user = ’root’;
ERROR 1054 (42S22): Unknown column '’root’' in 'where clause'

更改字段时出现错误,查了许久发现是root密码设置简单,而系统默认validate_password_policy为1,需修改为更低级别。(参照https://www.cnblogs.com/ivictor/p/5142809.html)

mysql> set global validate_password_policy=0;

Query OK, 0 rows affected (0.00 sec)

mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select host,user,authentication_string from user;
+-----------+---------------+-------------------------------------------+
| host | user | authentication_string |
+-----------+---------------+-------------------------------------------+
| % | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| localhost | mysql.session | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| localhost | mysql.sys | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+-----------+---------------+-------------------------------------------+

3,测试结果

 

posted on 2018-03-29 16:15  君未  阅读(281)  评论(0编辑  收藏  举报