MySQL拒绝访问报错not allowed to connect this MySQL server

MYSQL报如下错误,截取部分:

message from server: "Host '****' is not allowed to connect to this MySQL server

可能是你的帐号不允许从远程登陆,只能在localhost上登录,下面可行的方法,可以在其它任何的主机上登录

改表法

首先,进入localhost那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

$ mysql -u root -p
mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql> select host, user from user; # 查看结果

授权法
同样,进入localhost那台电脑,登入mysql后
如果你想允许root用户使用yourpassword从任何主机连接到mysql服务器的话。

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;

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

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES

这样就可以在其它任何的主机上以root身份登录啦!

如需转载,请注明出处: https://www.chadou.me/p/94

最新发布