How to solve "Can't connect to local MySQL server through socket" error? I kept getting this following error every time I tried to restart MySql. It was working fine before I changed the default data directory.  


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


I know there are other solutions posted by others but none of them worked for me.
Check the folowing


First check if another instance is runnig in the same machine

ps ax | grep mysql
Then, check if your file my.cnf (probably in /etc/mysql/ folder) is correctly configured with    




[mysqld]
datadir = /var/lib/mysql/
socket = /var/lib/mysql/mysql.sock



Next, you have changed the default data directory, did you gave the right permissions to the new directory now   



 chown mysql:mysql -R /var/lib/mysql/*
 chmod 755 -R /var/lib/mysql/*




After changing the permission restart the service and check  

service mysql restart