If your MySQL connection is failing and returning the message ERROR 2002 (HY000): Can’t connect to local MySQL server through socket, then chances are your MySql.sock file is missing or has been deleted.
By following these steps, you’ll be able to diagnose and determine which actions must be taken to get your MySql.sock file back in working order.
Locating a Missing MySql.sock File
To locate a missing mysql.sock file, use the following procedure:
- THIS IS THE MOST IMPORTANT STEP! Back up the /var/lib/mysql directory using the following command
# cp -fr /var/lib/mysql /var/lib/mysql.old
- Next, check /var/lib/mysql and /tmp for the .sock file (is it in both places?)
- Use this command to recreate the symbolic link to the .sock file:
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
- Now check the permissions of the /var/lib/mysql. It should be 0755 and mysql:root. If not:
# chmod 0755 /var/lib/mysql
# chown mysql:root /var/lib/mysql
- cat /etc/passwd to make sure that the mysql user is there.
- Does /var/lib/mysql/mysql/host.MYI exist? If not then:
# chmod -R 0660 /var/lib/mysql/mysql
# chown -R mysql:mysql /var/lib/mysql/mysql
- Now try to force an update:
# /scripts/mysqlup --force// for cPanel servers only
- If all else fails, then you may have a corrupted table. Now before you do this, TRIPLE CHECK that you have backed up the /var/lib/mysql directory. It fact, check it 4 times!
# rm -fr /var/lib/mysql
# rm -f /usr/sbin/mysqld
Then force another update:
# /scripts/mysqlup --force
- Now if all if this did not help, then try:
# /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/Server_HostName.pid --skip-locking &
Need More Personalized Help?
If you have any further issues, questions, or would like some assistance checking on this or anything else, please reach out to us from your my.hivelocity.net account -> Support and provide your server credentials within the encrypted field for the best possible security and support.
If you are unable to reach your my.hivelocity.net account or if you are on the go, please reach out from your valid my.hivelocity.net account email to us here: email@example.com. We are also available to you through our phone and live chat system 24/7/365.