Main Content

Cant connect to local MySQL server through socket /tmp/mysql.sock

Archive - Originally posted on "The Horse's Mouth" - 2009-10-17 22:22:56 - Graham Ellis

Q Have you ever had the error message Can't connect to local MySQL server through socket '/tmp/mysql.sock' from your PHP program. It's one that I see quite often, but it doesn't seem all that well documented ... so what's the cause, and the cure?

A The error message seems to occur if you delete your MySQL installation and re-install - something we do very frequently during our training. You need to remember to delete the /etc/my.cnf ~/my.cnf and data and spool directories before you re-install if you want a clean start.

If you have the error message above and want a temporary fix, try connecting to "127.0.0.1" and you'll probably find it will work ;-)