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

David Carr

Development

I had a crash after a reboot, then MySQL would not run, the error I was getting was:

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

I tried to kill the PID which is what most posts recommend, but the error remained 

This command did the trick for me, my installed MySQL version is just mysql if you're is like mysql@5.7 then adjust the name on the end of the command.

sudo chown -R _mysql:mysql /usr/local/var/mysql && sudo brew services restart mysql

Thank you to the StackOverflow user FooBar

 

Another approach is to change MySQL Permissions:

sudo chown -R _mysql:mysql /usr/local/var/mysql

Then start MySQL

sudo mysql.server start

Copyright © 2006 - 2024 DC Blog - All rights reserved.