解决Mysql链接报1130错误

in 干货分享 with 0 comment

报错内容

mysql权限被拒绝.png

mysql用户无权限.png
1045 - Access denied for user 'root'@'xx.xx.xx.xx' (using password: YES)字面意思,权限被拒绝
1130 - Host'xx.xx.xx.xx'is not allowed to connect to this MySQL server也是字面意思,不允许该主机连接到MySQL

查看权限

mysql> select User,host from mysql.user;
+---------------+-----------+
| User          | host      |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

解决方法

MySQL默认root用户只允许localhost本机登录,执行以下命令添加用户为%不限制链接地址
grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码"; 

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Linux6.cn' ;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select User,host from mysql.user;
+---------------+-----------+
| User          | host      |
+---------------+-----------+
| root          | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)

OK,现在已经可以使用新添加的用户和新密码在自己电脑上使用工具链接了
附送安装Mysql步骤:Centos7使用yum安装Mysql

Responses