[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: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

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