Software⏱️ 4 min read📅 2026-06-15

How to Fix error 2002 Error – Error starting MySQL server (error 2002)

MySQL server connection error

Quick Answer: Check if the MySQL socket file exists and is accessible.

The error message 'ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)' indicates that the MySQL server is unable to establish a connection with the client due to a missing or invalid socket file. This issue affects users who are trying to start the MySQL server on their local machine.

This error can be frustrating for developers and database administrators as it prevents them from accessing and managing their MySQL databases. In this guide, we will walk you through the possible causes of this error and provide steps to resolve the issue.

🔍 Why This Happens

  • The primary cause of this error is that the MySQL socket file '/tmp/mysql.sock' does not exist or is not readable by the current user running the MySQL server. This can happen if the MySQL server was installed without creating the necessary directories or if the permissions on the socket file are incorrect.
  • An alternative reason for this error is that the MySQL socket file is being used by another process, such as a web application or another database management system. In this case, the MySQL server may not be able to establish a connection with the client due to a conflict with the existing socket file.

🚀 How to Resolve This Issue

Fixing the Socket File Permissions

  1. Step 1: Step 1: Open a terminal as the root user and navigate to the directory where the MySQL socket file is located. The default location for the socket file is /var/run/mysqld/mysqld.sock.
  2. Step 2: Step 2: Use the 'chown' command to change the ownership of the socket file to the current user running the MySQL server. For example, if you are using a non-root user named 'mysqluser', you can use the following command: chown mysqluser:mysql /var/run/mysqld/mysqld.sock.
  3. Step 3: Step 3: Use the 'chmod' command to change the permissions of the socket file to allow read and write access for the current user. For example, if you are using a non-root user named 'mysqluser', you can use the following command: chmod 660 /var/run/mysqld/mysqld.sock.
  4. Step 4: Step 4: Restart the MySQL server service to apply the changes. You can do this by running the following command: service mysql restart
  5. Step 5: Step 5: Verify that the socket file exists and is readable by the current user by running the following command: ls -l /var/run/mysqld/mysqld.sock

Removing the MySQL Socket File

  1. Step 1: Step 1: Stop the MySQL server service to prevent any further conflicts. You can do this by running the following command: service mysql stop.
  2. Step 2: Step 2: Remove the MySQL socket file using the 'rm' command. For example, you can use the following command: rm /var/run/mysqld/mysqld.sock
  3. Step 3: Step 3: Configure the MySQL server to use a different socket file location or disable the use of socket files altogether.
  4. Step 4: Note: Disabling the use of socket files may require changes to the MySQL configuration file (my.cnf or my.ini) and may not be recommended as it can affect the performance of the MySQL server.

✨ Wrapping Up

By following these steps, you should be able to resolve the 'ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)' error and start your MySQL server successfully. Remember to verify that the socket file exists and is readable by the current user after applying the changes.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions