这个问题与以下问题有关:
我正在本地机器上配置一个新的 MySQL (5.1) 服务器。我需要提供对数据库的远程访问。我做了以下步骤:
在my.cnf中注释bind-address
:
# bind-address = 192.168.1.3
授予权限:
GRANT ALL PRIVILEGES ON *.* TO 'nickruiz'@'%' IDENTIFIED BY PASSWORD 'xxxx';
为防火墙配置 iptables
sudo iptables -I INPUT -p udp --dport 3306 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 3306 --syn -j ACCEPT
sudo iptables-save
重启mysql服务器sudo/etc/init.d/mysql restart
在测试时,我得到以下信息:
局域网:
mysql -h 192.168.1.3 -u nickruiz -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 95
Server version: 5.1.63-0ubuntu0.11.04.1 (Ubuntu)
远程:
mysql -h 1xx.xx.4.136 -u nickruiz -p
ERROR 2003 (HY000): Can't connect to MySQL server on '1xx.xx.4.136' (111)
显然有什么问题让我无法使用我的全局 IP 地址。
注意事项:
有什么想法吗?
更新: telnet 似乎无法正常工作。
telnet 192.168.1.3 3306
Trying 192.168.1.3...
Connected to 192.168.1.3.
Escape character is '^]'.
E
5.1.63-0ubuntu0.11.04.1,0g8!:@pX;]DyY0#\)SIConnection closed by foreign host.
最佳答案
请检查您的监听端口:
netstat -nat |grep :3306
如果显示
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
远程连接没问题。
但在这种情况下,我认为你有
tcp 0 192.168.1.3:3306 0.0.0.0:* LISTEN
您的远程连接没问题。 您还应该检查您的防火墙(如果您使用 centos/redhat,则为 iptables)
services iptables stop
用于测试或使用:
iptables -A input -p tcp -i eth0 --dport 3306 -m state NEW,ESTABLISHED -j ACCEPT
iptables -A output -p tcp -i eth0 --sport 3306 -m state NEW,ESTABLISHED -j ACCEPT
还有一件事是检查您对远程连接的授予权限:
GRANT ALL ON *.* TO remoteUser@'remoteIpadress' IDENTIFIED BY 'my_password';
关于mysql - 错误 2003 (HY000) : Can't connect to MySQL server (111),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11758339/