本文介绍了错误2003(HY000):无法连接到MySQL服务器(111)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与以下问题有关:

This question is related to the following questions:

  • Can't connect to MySQL server error 111
  • Trying to connect to remote MySQL host (error 2003)

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

I am configuring a new MySQL (5.1) server on my local machine. I need to provide remote access to the database. I did the following steps:

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

# bind-address      = 192.168.1.3

  • 授予特权:

  • Grant privileges:

    GRANT ALL PRIVILEGES ON *.* TO 'nickruiz'@'%' IDENTIFIED BY PASSWORD 'xxxx';
    

  • 设置路由器上的端口转发(TCP和UDP,端口3306、192.168.1.3)
  • 为防火墙配置iptables

  • Set port forwarding on router (TCP and UDP, port 3306, 192.168.1.3)
  • Configure iptables for firewall

    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

    测试时,我得到以下信息:

    When testing, I get the following:

    局域网:

    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地址.

    Clearly there's something wrong that's preventing me from being able to use my global IP address.

    注意:

    • 我尝试在同一台机器上测试远程连接,并且通过SSH从远程计算机.
    • 我不确定我的ISP是否给我提供了静态IP.
    • I've tried testing the remote connection on the same machine and alsovia SSH from a remote machine.
    • I'm not sure if my ISP has given me a static IP.

    有什么想法吗?

    更新:telnet似乎无法正常工作.

    Update:telnet doesn't seem to be working.

    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
    

    没关系,您可以进行远程连接.

    Thats is ok for your remote connection.

    但是在这种情况下,我认为您有

    But in this case i think you have

    tcp        0     192.168.1.3:3306            0.0.0.0:*               LISTEN
    

    那对您的远程连接是可以的.您还应该检查防火墙(如果为centos/redhat,则为iptables)

    Thats is ok for your remote connection.You should also check your firewall (iptables if you centos/redhat)

    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
    

    还有另一件事要检查您对远程连接的授予权限:

    And another thing to check your grant permission for remote connection :

    GRANT ALL ON *.* TO remoteUser@'remoteIpadress' IDENTIFIED BY 'my_password';
    

    这篇关于错误2003(HY000):无法连接到MySQL服务器(111)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 08-10 21:58