I created a MySql instance the other day, and today I wanted to connect my application server to that database server.

While connecting from my application server I kept getting this error.

Lost connection to MySQL server at ‘reading initial communication packet’, system error: 113

After searching many forum threads, I finally noticed that the issue was with MySql needing a bind address to know who is allowed to connect to the MySql instance.

So I edited /etc/my.cnf and this was the contents

# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).

# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0



Next I needed to restart MySql in order for these changes to take affect.

/etc/init.d/mysqld restart

What I found is this was not the issue. The issue is that the default Firewall on CENTOS is enabled, but does not allow for port 3306 to be accessed outside of localhost.

I was able to fix this by modifying the file /etc/sysconfig/iptables

Just add a line similar to the following to the end of iptables

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject

Then I restarted the firewall. run the command “service iptables restart” and you should be good to go. Must be root.

That takes care of the firewall, but now I need to tell MySql to allow the user to connect from a different machine.
I was getting this error

Could not connect to the server 'data.baselogic.com'

Host '' is not allowed to connect to this MySQL server

And this tells me that MySql itself is not allowing the connection to be made.

mysql -u root -p

Then Issuing the grant:

mysql> GRANT ALL ON fooDatabase.* TO fooUser@'' IDENTIFIED BY 'my_password';

Then I was able to connect

# mysql -u fooUser -p -h
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> _

Seemed to be quite a bit of trouble for an error

Mick Knutson

Java, JavaEE, J2EE, WebLogic, WebSphere, JBoss, Tomcat, Oracle, Spring, Maven, Architecture, Design, Mentoring, Instructor and Agile Consulting. http://www.baselogic.com/blog/resume

View all posts
  • kneal

    Thanks very much Mick. The solution worked fine.

Java / JavaEE / SpringFramework Channel

BLiNC Supporters

BLiNC Adsense