MySQL连接报ERROR 2003(HY000) Can‘t connect to MySQL server on ‘xxxIP‘(113)

MySQL连接远程服务器ERROR 2003(HY000)

1.问题描述

[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.解决思路

2.1登录远程服务器,查看服务器版本

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

CentOS release 6.4 (Final)

CentOS7及7以上的版本用的是firewall防火墙

CentOS7以下用的是iptables防火墙

2.2查看iptables状态

[root@test~]#iptables -L

或者

[root@test~]#service iptables status

表格: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

查看得知没有开放3306端口,需加3306端口开放

2.3开放3306端口

编辑/etc/sysconfig/iptables,在REJECT上面一行添加如下代码

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

后保存退出

或者直接执行如下命令

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

然后再执行重启命令

[root@test~]#service iptables save

[root@test~]#service iptables restart

注意点:

添加完,ACCEPT必须都在REJECT上方,如果使用的是编辑方式,先执行restart再执行save

猜你喜欢

转载自blog.csdn.net/Aaron_ch/article/details/113007381