mysql远程连接:ERROR 1130 (HY000): Host '*.*.*.*' is not allowed to connect to this MySQL server解决办法

时间:2022-09-19 21:39:30

录制项目中用到了mysql,今天在测试时发现无法远程连接mysql数据库,原来是mysql默认不允许远程连接。

搜索了一下,找到了解决办法,记录在此以备日后查用。  

 

(1)一开始我使用root用户和mysql服务器ip远程连接,直接报错:

[root@chu Record]# mysql --host=192.168.110.68 --user=root --password
Enter password: 
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.110.68' (111)

 原来是

默认情况下Mysql只允许本地登录,所以需要修改配置文件将地址绑定给注释掉:
vim /etc/mysql/my.cnf
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1 <---注释掉这一行就可以远程登录了 

参见:http://blog.sina.com.cn/s/blog_60fcb5a10100qkyb.html

(2)修改后继续报错: 

1  [root@chu Record]# mysql --host=192.168.110.68 --user=root --password
2 Enter password:
3 ERROR 1130 (HY000): Host '192.168.56.123' is not allowed to connect to this MySQL server

如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; 

参见:http://blog.csdn.net/rongjch/archive/2006/02/23/607124.aspx

 

这样操作后,问题解决了。