Recently I started receiving errors when I tried to connect to MySQL using command line or PHPMyAdmin. In command line I would get “ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)”, and with PHPMyAdmin I would get “#2002 – The server is not responding (or the local MySQL server’s socket is not correctly configured)”.
The system in question is my Dell Inspiron 1720 running Hardy Heron Ubuntu. I knew of a few changes to my system, but none of them seemed to have caused the problem. So I hunted for a few days trying to figure it out. I performed multiple searches on the net, and each led me to a dead end. Many said, “Set this … in your php.ini” or “Set that … in your my.cnf”, and some even said Apache was to blame. However, I found the solution to be very simple.
MySQL was expecting the mysql.sock to be located in ‘/tmp/mysql.sock’. However, for some reason it had moved or the symbolic link to it’s actual location was deleted by some update or install I did recently.
I fixed the problem by adding a symbolic link to the actual home of mysqld.sock, which was /var/run/mysqld/mysqld.sock. Here is how I created the symbolic link: (at the command line)
sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
sudo puts us in super user mode, “ln -s” creates a symbolic link followed by the target the links sould point to and last by the location of the link.
Edited on Sep. 26th with update below:
The fix above did not work as a permanent fix. I found that whenever I rebooted the OS it forced me to recreate the symbolic link. MySQL was failing to recreate the symbolic link on it’s own. To permanently fix the issue I needed to add the creation of the symbolic link to my SESSION startup. Here is how I did that:
By going to the System->Preferences->Sessions to edit the Startup Programs. I added an item that automatically issues the command above, but without the “sudo”.