一、改表法 
在localhost登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,将”localhost”改称”%”

mysql -u root -p

mysql>use mysql;

mysql>update user set host =’%'where user =’root’;

mysql>flush privileges;

二、授权法 
例如: 你想myuser使用mypassword(密码)从任何主机连接到mysql服务器的话。

mysql>grant all privileges on *.* to 'myuser'@'%' identified by 'mypassword';

如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用mypassword作为密码

mysql>grant all privileges on *.* to 'myuser'@'192.168.1.6' identified by 'mypassword';

刷新授权:mysql>flush privileges;

此时,你的Mysql就可以被远程连接了。

关闭授权
revoke all on *.* from dba@localhost;

如果还不能连接,就可能是防火墙的锅了

查看端口号3306 是否开启:

firewall-cmd --zone= public --query-port=3306/tcp

那怎么开启端口呢

永久开启3306端口

firewall-cmd --zone=public --add-port=3306/tcp --permanent

重新载入

firewall-cmd --reload

移除端口号

firewall-cmd --zone= public --remove-port=3306/tcp --permanent

--zone #作用域

Copyright © 2014-2024 it689.com (京ICP备12032795号-2) 版权所有 Power by IT689