MySQL Database Error Code 2002: How to Fix It

Medium 10-20 minutes High Severity Verified June 2026
Error Code
ERROR 2002 (HY000)
Brand
MySQL
Product Type
database
Severity
High
DIY Difficulty
Medium
Estimated Fix Time
10-20 minutes
MySQL Error 2002 (HY000) occurs when your application cannot connect to the MySQL database server through a Unix socket. This typically happens when the MySQL daemon (mysqld) service is not running, the socket file path is incorrect, or there are permission issues with the socket file.
Ad

Tools You'll Need

How to Fix Error Code ERROR 2002 (HY000)

  1. Check MySQL Service Status

    Always backup your database before making any changes to MySQL configurations or performing restarts.
  2. Start MySQL Service

  3. Verify Socket File Location

  4. Check Socket File Permissions

  5. Use TCP Connection Instead

  6. Check MySQL Error Logs

  7. Restart MySQL Service

    Restarting MySQL will temporarily disconnect all active database connections.
Ad

When to Call a Professional

Contact a database administrator or system administrator if the MySQL service fails to start after following these steps, if you encounter disk space issues, corrupted data files, or if you're working with a production database that requires zero downtime.

Frequently Asked Questions

What causes MySQL Error 2002?
MySQL Error 2002 is caused by the MySQL daemon not running, incorrect socket file path in configuration, permission issues with the socket file, or network connectivity problems preventing socket communication.
How do I know if MySQL is running?
Check MySQL status using 'systemctl status mysql' on Linux, 'brew services list' on macOS, or the Services panel on Windows. You can also try connecting with 'mysql -u root -p' command.
Can I use TCP instead of Unix socket?
Yes, you can connect using TCP by replacing 'localhost' with '127.0.0.1' in your connection string, or by adding '--protocol=TCP' parameter. TCP connections are slightly slower but more reliable across different systems.
Where is the MySQL socket file located?
Common socket file locations include /tmp/mysql.sock, /var/run/mysqld/mysqld.sock, and /var/lib/mysql/mysql.sock. Check your my.cnf configuration file for the exact path specified in the 'socket' parameter.
Why does MySQL 2002 error happen after system restart?
After system restart, MySQL service may not start automatically, the socket file might be deleted from /tmp directory, or file permissions may have changed. Enable MySQL auto-start and verify socket file persistence.