If you are getting this error
ERROR 2002 (HY000: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)
then these steps should help you solve it.
- Ensure that the user ‘mysql’ has complete access to the mysql folder and all the files in it.
chmod -R mysql.root /var/lib/mysql/*
90% of the time this should solve your issue. If not, try the next step.
- Try to locate the path to the file ‘mysqld.sock’.
Case 1:
If you find it and it is not in the location as specified in the error message then create a symlink to the file in the expected directory. For example, in our error message mysqld.sock is expected to be in the var/run/mysqld/ folder.
Case 2:
You cannot locate a file ’mysqld.sock’ at all. In this case you try to locate ‘mysqld’
(Remember that mysqld is NOT a folder but a file.)
locate mysqld
Create a symlink to this file in the expected directory. For example:
cd /var/run/mysqld/
ln -s /usr/sbin/mysqld mysqld.sock
Thats its! Now when you restart your MySQL all should work fine.
/etc/init.d/mysql restart
Note:
Our server is Ubuntu 8.04 server with MySQL Ver 14.12 Distrib 5.0.51a
When the MySQL partition became full the MySQL service stopped(crashed). Restarting the service after creating free space resulted in the error discussed.
Reference link: http://forums.mysql.com/read.php?11,9689,14974#msg-14974