MySQL connection reports ERROR 2003 (HY000) Can't connect to MySQL server on'xxxIP' (113)

MySQL connect to remote server ERROR 2003 (HY000)

1. Problem description

[root@test ~]# mysql -h 192.168.xx.xx -uroot -p
Enter password:

ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.xx.xx' (113)

[root@test ~]# perror 113

OS error code 113: No route to host

2. Solutions

2.1 Log in to the remote server and check the server version

[root@test~]#cat /etc/redhat-release

CentOS release 6.4 (Final)

CentOS7 and above versions use firewall firewall

Below CentOS7 is iptables firewall

2.2 View iptables status

[root@test~]#iptables -L

or

[root@test~]#service iptables status

Table: filter

Chain INPUT (policy ACCEPT)

num target prot opt source destination

1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED

2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0

3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0

4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22

5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)

num target prot opt source destination

1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)

num target prot opt source destination

Check that port 3306 is not open, and port 3306 needs to be opened

2.3 Open port 3306

Edit /etc/sysconfig/iptables and add the following code in the line above REJECT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

Save and exit

Or directly execute the following command

[root@test ~]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

Then execute the restart command

[root@test~]#service iptables save

[root@test~]#service iptables restart

important point:

After adding, ACCEPT must be above REJECT. If you are using edit mode, execute restart first and then save

Guess you like

Origin blog.csdn.net/Aaron_ch/article/details/113007381