This happened to me recently as I switched to a different network. Everything was working and I had not changed any setting whatsoever. But I failed to login to MySQL and got errors like
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
STOPPING server from pid file /usr/local/mysql/data/SOMEPIDFILEHERE.pid
I was seriously considering reinstalling but…I *knew* it was all running good before so there must’ve been something else.
The problem was that mysql was configured with ‘localhost’ (fine) but for some reason my hostname was not ‘localhost’ on the new network, instead I had the network’s address.
$ sudo hostname localhost <or whatever you set up with, e.g. 127.0.0.1 before>
$ sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist
$ sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist
Voila it worked after that!
$ mysql -u root [-p]