相关推荐recommended
MySQL登录报错1130:1130 Host ***.***.***.*** is not allowed to connect to this MySQL server
作者:mmseoamin日期:2023-12-05

一、问题发现

​ 从Navicat登录MySQL时报错:1130 Host ... is not allowed to connect to this MySQL server

​ 原因分析:报错信息表示需要连接的数据库不允许其他主机进行访问,这是因为MySQL的系统数据库mysql中的user表没有配置远程访问主机的登录信息,只有localhost本地登录的信息(如下图);

MySQL登录报错1130:1130 Host ***.***.***.*** is not allowed to connect to this MySQL server,在这里插入图片描述,第1张

二、解决方法

例子:比如希望以XXX用户从ip为XXX.XXX.XX.X的主机登录MySQL数据库,解决步骤如下:

#在MySQL所在主机上使用root用户进行登录
mysql -u root -p
#进入数据库mysql
use mysql;
#进行授权
grant all privileges on \*.\* to 'XXX'@'XXX.XXX.XX.X' identified by 'passwords' with grant option;

MySQL登录报错1130:1130 Host ***.***.***.*** is not allowed to connect to this MySQL server,在这里插入图片描述,第2张

以上操作只是允许XXX用户从指定ip地址登录MySQL,如果希望XXX用户可以从任意ip地址登录MySQL,则可以做如下操作:

grant all privileges on \*.\* to 'XXX'@'%' identified by 'passwords' with grant option;

修改完成后,即可通过navicat登录:

MySQL登录报错1130:1130 Host ***.***.***.*** is not allowed to connect to this MySQL server,在这里插入图片描述,第3张