Fix MySQL 113 error

Yesterday I got 113 error code from MySQL when I try to test access it from network.

The machine have 2 lan cards (192.168.103.254 and 192.168.1.89). Both of them are active and I can ping it.

# mysql -ualam -p -h 192.168.103.254
Enter password:
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘192.168.103.254’ (113)
# mysql -ualam -p -h 192.168.1.89
Enter password:
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘192.168.1.89’ (113)

After see the major.io post about MySQL error codes . I find out that the problem might came from firewall.

Check current firewall state :

# cat /etc/sysconfig/iptables

# Generated by iptables-save v1.3.5 on Thu Aug 13 13:13:27 2015
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [389671:206304610]
:RH-Firewall-1-INPUT – [0:0]
-A INPUT -p tcp -m tcp –dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp –dport 8082 -j ACCEPT
-A INPUT -p tcp -m tcp –dport 80 -j ACCEPT
-A INPUT -j RH-Firewall-1-INPUT
-A INPUT -i eth0 -p tcp -m tcp –dport 3306 -j ACCEPT
-A INPUT -i eth1 -p tcp -m tcp –dport 3306 -j ACCEPT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp -m icmp –icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p esp -j ACCEPT
-A RH-Firewall-1-INPUT -p ah -j ACCEPT
-A RH-Firewall-1-INPUT -d 224.0.0.251 -p udp -m udp –dport 5353 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state –state NEW -m tcp –dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited
COMMIT
# Completed on Thu Aug 13 13:13:27 2015

Well, this line :

-A INPUT -j RH-Firewall-1-INPUT

is the source of problem. Edit the order of rule and restart iptables.

# mysql -ualam -p -h 192.168.1.89
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6152
Server version: 5.1.58-log MySQL Community Server (GPL) by Utter Ramblings

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

Mission accomplish 🙂