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
Ad
Tools You'll Need
- Command line terminal access
- Text editor for configuration files
- Administrative privileges
How to Fix Error Code ERROR 2002 (HY000)
-
Check MySQL Service Status
Always backup your database before making any changes to MySQL configurations or performing restarts. -
Start MySQL Service
-
Verify Socket File Location
-
Check Socket File Permissions
-
Use TCP Connection Instead
-
Check MySQL Error Logs
-
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.