gpt4 book ai didi

mysql - 错误 2003 (HY000) : Can't connect to MySQL server (111)

转载 作者:IT老高 更新时间:2023-10-28 12:40:19 28 4
gpt4 key购买 nike

这个问题与以下问题有关:

我正在本地机器上配置一个新的 MySQL (5.1) 服务器。我需要提供对数据库的远程访问。我做了以下步骤:

  1. 在my.cnf中注释bind-address:

    # bind-address      = 192.168.1.3
  2. 授予权限:

    GRANT ALL PRIVILEGES ON *.* TO 'nickruiz'@'%' IDENTIFIED BY PASSWORD 'xxxx';
  3. 在路由器上设置端口转发(TCP 和 UDP,端口 3306、192.168.1.3)
  4. 为防火墙配置 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
  5. 重启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.

最佳答案

请检查您的监听端口:

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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com