ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib /mysql/mysql.sock’


If you get the error like:

[root@tutorialspots ~]# service mysql restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL... ERROR!

[root@tutorialspots ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib
/mysql/mysql.sock' (2 "No such file or directory")

Solution:

Step 1: Find in file my.cnf (or my.ini) i.e. /etc/my.cnf, the variable pid-file, if not exists, you must add manually:

pid-file=/var/lib/mysql/tutorialspots.com.pid

Step 2: use SSH command:

touch /var/lib/mysql/tutorialspots.com.pid
touch /var/lib /mysql/mysql.sock

Now you can check the status of service mysql (or mysqld)

service mysql status

If you get the error:

[root@tutorialspots ~]# service mysql status
 ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists

You must delete file /var/lock/subsys/mysql

rm /var/lock/subsys/mysql

Leave a Reply