Black Friday sale is now on! 50% off Laravel: The Modular Way. Learn more

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

Laravel Modules Book by David Carr

Help support the blog so that I can continue creating new content!

Subscribe to my newsletter

Subscribe and get my books and product announcements.

© 2009 - 2022 DC Blog. All code MIT license. All rights reserved.