【发布时间】:2012-07-30 07:05:37
【问题描述】:
这个问题与以下问题有关:
我正在本地机器上配置一个新的 MySQL (5.1) 服务器。我需要提供对数据库的远程访问。我做了以下步骤:
-
在my.cnf中评论
bind-address:# bind-address = 192.168.1.3 -
授予权限:
GRANT ALL PRIVILEGES ON *.* TO 'nickruiz'@'%' IDENTIFIED BY PASSWORD 'xxxx'; - 在路由器上设置端口转发(TCP 和 UDP,端口 3306、192.168.1.3)
-
为防火墙配置 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 地址。
注意事项:
- 我试过在同一台机器上测试远程连接 通过远程机器上的 SSH。
- 我不确定我的 ISP 是否给了我一个静态 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.
【问题讨论】:
-
你的 my.cnf 中没有
skip-networking,是吗? -
还有
telnet 192.168.1.3 3306。如果它打开任何类型的提示,则端口正在侦听并接受连接。 -
my.cnf 中没有跳过网络。
-
Telnet 不工作。见上文。
-
其实就是telnet工作正常。如果您获得连接和
Escape character is ^],那么您已经成功建立了连接。你不会看到 MySQL 提示,但你有一个到 MySQL 端口的原始连接,所以它正在正确地监听那个地址!
标签: mysql linux remote-access mysql-error-2003