HostOnNet Blog

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

Looking for Linux Server Admin or WordPress Expert? We can help.

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
/var/lib/mysql/mysql.sock
/usr/local/lib/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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.