HostOnNet Blog

MySQL Error: Can’t connect through socket /var/tmp/mysql.sock

On a Cpanel/WHM server running RHEL, after rebooting MySQL stoped working for all sites hosted on the server. I tried restarting MySQL, but it won’t solved the problem. Sites still shows the error message

Warning: mysql_pconnect(): Can’t connect to local MySQL server through socket ‘/var/tmp/mysql.sock’ (2) in /home/flashhos/public_html/index.php on line 9
Problem with dB connection!

The problem is, MySQL could not find the socket at /var/tmp/mysql.sock

So i locked the orginal location of socket with

# locate mysql.sock

Found two files. So i go to /var/tmp/ and created a sym link to /var/lib/mysql/mysql.sock

# cd /var/tmp
# ln -s /var/lib/mysql/mysql.sock

After doing this, restarted MySQL server

service mysql stop
service mysql start

Now everything working fine.

Posted in Database. Bookmark the permalink.