mysql连接的时候,null, message from server: “Host ‘xx.xx.xx.xx‘ is not allowed to connect to this MySQL server“

发布时间 2023-08-06 17:49:19作者: sharestone

连接mysql的时候,提示“null, message from server: “Host ‘xx.xx.xx.xx‘ is not allowed to connect to this MySQL server“”

解决

出现这个提示,是由于我们使用root用户登录时,没有给root用户设置能访问的机器,所以我们设置一下,就可以了。

第一步:登录mysql:

输入 mysql -u root -p 命令,键入密码,连接成功。

第二步:切换数据库

输入use mysql 将数据库切换到mysql库

第三步:修改root用户的权限

输入 update user set host = '%' where user = 'root' ;(注意加分号结尾,host = '%'表示允许所有机器能访问root用户)

第四步:刷新权限

输入flush privileges;刷新权限,使修改的root权限生效。

小结

完成以上四步后,再次尝试连接,就可以在自己的机器上连接服务器上的mysql了。