Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
934 views
in Technique[技术] by (71.8m points)

linux - ERROR 2003 (HY000): Can't connect to MySQL server (111)

This question is related to the following questions:

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. Comment bind-address in my.cnf:

    # bind-address      = 192.168.1.3
    
  2. Grant privileges:

    GRANT ALL PRIVILEGES ON *.* TO 'nickruiz'@'%' IDENTIFIED BY PASSWORD 'xxxx';
    
  3. Set port forwarding on router (TCP and UDP, port 3306, 192.168.1.3)
  4. 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
    
  5. Restart mysql server sudo /etc/init.d/mysql restart

When testing, I get the following:

LAN:

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)

Remote:

mysql -h 1xx.xx.4.136 -u nickruiz -p
ERROR 2003 (HY000): Can't connect to MySQL server on '1xx.xx.4.136' (111)

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

Notes:

  • I've tried testing the remote connection on the same machine and also via SSH from a remote machine.
  • I'm not sure if my ISP has given me a static IP.

Any ideas?

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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Please check your listenning ports with :

netstat -nat |grep :3306

If it show

 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 

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

services iptables stop

for testing or use :

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';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...