主机不能远程连接mysql数据库的解决办法

1。改表法。在数据库所在机器登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,把"localhost"改称"%"

mysql -u root -p 
mysql>use mysql; 
mysql>select 'host' from user where user='root'; 
mysql>update user set host = '%' where user ='root'; 
mysql>flush privileges; 
mysql>select host,user   from user where user='root'; 

重起mysql服务即可完成。

  1. 授权法。在数据库所在机器登入mysql后,直接进行授权

grant all privileges on . to 'root'@'%' identified by 'password' with grant option;

猜你喜欢

转载自blog.51cto.com/xiaoahehe/2178794