Intermittent "Can't connect to MySQL server"

Hi there,

Recently, I started getting small periods of intermittent connection errors about once every hour, lasting for about 1 to 5 minutes each time:
Can’t connect to local MySQL server through socket
‘/var/lib/mysql/mysql.sock’

I enabled the error log and did some other monitoring and established 2 things:

  • the server doesn’t crash/restart, it keeps running throughout the errors
  • the errors do not match the load on the website, as sometimes when 500 users are online there are no errors, but when 300 are online they may by prolific

I checked many forums and then made 4 changes:

  • changed the directory containing the mysql.sock file so only file owners or superusers can delete files from it
  • I changed the default socket file setting in both my.cnf and php.ini
  • I read about SELinux causing such a problem, so I disabled SELinux completely, rebooted the server and double-checked that it is indeed disabled.

Despite all these changes, I still get the errors. I then read that there is a workaround by using TCP/IP instead of the sock file. I tried that, but I still get the error intermittently in the form of:
Can’t connect to MySQL server on 127.0.0.1

This is a extremely frustrating problem, it’s been bugging us for weeks, anyone who can offer some help - it will be greatly appreciated!

MySQL server 4.1.20, PHP 4.3.9, client API 4.1.20, CentOS 4.3, Intel P4 2.8GHz 1GB RAM

Please always paste full error message as you get it from the program. In your error message the most important item - error code is missing.

It could be simply socket file itself or directory permissions are incorrect and many other things.

I have now also increased the amount of open files allowed by the operating system from 1000 to 30000. Still the same problem. Anyone, please help!

The error number is 2002. I’m still plagued by this problem, I even had to issue a refund to one of my customers. Please help!

This is not the real code this is code for can’t connect message.

Simply copy and paste full output.

What I’m looking for is OS error code which tells why it can’t connect.

Where can I get that error code?