% mysql -uroot
ERROR 2002 (HY000): Can't 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>
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!