[macOS] Fix: MySQL ERROR 2002 (HY000): Cant connect to local MySQL server through socket /tmp/mysql.sock (2)


% mysql -uroot 

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

If you have installed MySQL server using homebrew package manager and when you try to start it and you get ERROR 2002 then you need to start the service using the brew services start command.

The brew services is used to manage background services using the daemon manager launchctl on macOS.

Fix:

% brew services start mysql

Once complete, you can connect to MySQL via the terminal.

% mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.33 Homebrew

mysql>  

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap