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

So you ran an upgrade, or got carried away tweaking things on your server, and now MySQL is acting like an island of its own. Your websites can’t connect, your phpmyadmin can’t connect, and you are miserable.

You get errors like

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysqld.sock'

and, you being a n00b like me, are at your wits end.

I may have a quick fix as long as the error is 2002 and it is complaining about a socket.

Go to your MySQL configuration file [which on Ubuntu is /etc/mysql/my.cnf ]

There, copy the socket mysqld is using. It will be something like

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

Copy the line that says socket=/whatever/address/to/the/file.sock

See if there is a block for [client] that mentions socket. If there isn’t, make one below the block for [mysqld] and paste your socket line. If there is, fix the location to match.

Try now. No restart or anything needed. If it will work, it will work right away. If you have done good things in your life and deserve a break, this should put you out of your misery. 😀 It is among the likeliest culprits if new files and upgrades and such have happened.

If this doesn’t happen, then I would investigate to see if that location exists, has right permissions and such things…. or someone mentioned other checking for other configurations that may be messing with this – which I can’t even imagine where to begin.

Good Luck!


by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *