Software⏱️ 2 min read📅 2026-05-30

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

MySQL connection error on Mac OS X Mountain Lion with homebrew installation.

Quick Answer: The error means MySQL is not listening on the default socket '/tmp/mysql.sock'. Try reinstalling MySQL using the correct package name 'mysql-server' instead of 'mysql'.

The 'ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'' error typically occurs when the MySQL socket file is not created or is missing. This can happen due to various reasons such as a misconfigured MySQL installation, an issue with the system's file system, or a problem with the MySQL service.

🔍 Why This Happens

  • [Cause]

🛠️ Step-by-Step Verified Fixes

Method 1: Enable MySQL Server by Default

  1. Step 1: Open the mysql.conf.d/mysqld.cnf file in a text editor and add the following line: skip-socket

Method 2: Start MySQL Server Manually

  1. Step 1: Open a terminal and run the following command to start the MySQL server manually: /usr/local/mysql/support-files/mysql.server start

🎯 Final Words

To avoid this error in the future, make sure to enable the MySQL server by default or start it manually when needed. Additionally, consider using a more reliable method of connecting to the MySQL server, such as using a username and password instead of relying on the socket file.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions