Here's an interesting one that does not seem to fall into any of the mysql connection issues I've read about or searched for: On an Ubuntu 12.04 box I had some system updates waiting to install, and I took care of that this evening. After the install, I started seeing some errors in my syslog complaining about a particular php script that could no longer connect to the mysql instance on the box. Here is the specific error:

PHP Warning:  mysql_connect(): Can't connect to MySQL server on '' (4) 

Now, the server's IP address is, and I've checked to make sure that I have mysql listening on so that I can connect using either "localhost" or "".

Here's where things get odd: From the local machine, if I try the following:

mysql -uroot -p -h192.168.0.40

I get this error:

ERROR 2003 (HY000): Can't connect to MySQL server on '' (110)

I've checked, and error 110 indicates an OS timeout, and error 2003 is the mysql generic "can't connect" error. This indicates that it is not permissions with the user.

However, if I do the same thing from a remote machine (say, from, I log right in with no problems.

Futher, other scripts on the local machine that connect to mysql using "localhost" for the host rather than "" connect with no problems. Also, I can connect via the mysql socket with no problems both from the command line and php scripts.

So, this feels like a networking issue of some kind on the local box, but there are no iptables rules on this box (it is firewalled externally) and I can't figure out what else may be causing this.

This problematic script worked perfectly prior to the latest system update.

For now, I'll simply change the script to connect via localhost, but I'd really like to know why it broke for 2 reasons:

  1. There may be other scripts that connect using that don't run very often which are now broken. Auditing them all will take more time than I feel like devoting at the moment.

  2. I'm curious, and want to know why it broke so I can fix it correctly.

Any help?

  • Maybe better for serverfault
    – Mike Brant
    Oct 29 '12 at 6:26
  • I am facing same issue, how did you fix it ? Dec 4 '13 at 7:13

If you really mean to access the server remotely, then open up the proper firewall port (default 3306).


Make sure MySQL user has the permission to connect from


I had this same problem, only being able to connect to the database on localhost or, and tried everything. I opened the firewall ports, tried editing the my.ini network configurations, and more.

SOLUTION (these are the steps I took to finally fix it):

  • Open MySQL Workbench
  • Log into the database as an administrator
  • Navigate to the Server menu up top
  • Select Users and Privileges
  • Make sure all accounts you are looking to connect with have % selected for the 'Limit to Hosts Matching:' section.

I had my root user set to localhost, which I assume is the default. Making that % instead of localhost fixed the problem for me.

Again, this is all assuming that your firewall ports are open and you have tried everything else.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy