ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
TL;DRThe MySQL command-line client cannot reach the database server on the same machine because the expected socket file is missing. This usually means the MySQL server process is not running or failed to start.
Most likely cause: MySQL server service is stopped or crashed
Try first: Check whether the MySQL server is running (systemctl status mysql)
Likely causes
- MySQL server service is stopped or crashedmost likely
- Socket file path in MySQL config does not match the actual locationpossible
- Permission or ownership problem on the /var/run/mysqld directoryless likely
How to fix it
Safest first: SafeChanges settingsDangerous
Check whether the MySQL server is runningSafe
Run this read-only command to see the current status of the MySQL service.
systemctl status mysqlCheck the MySQL error log for startup problemsSafe
Look at the recent lines of the log file to see why the server may have failed to start.
sudo tail -n 50 /var/log/mysql/error.logStart the MySQL server if it is not activeChanges settings
If the previous command shows it is inactive, start it with this command.
sudo systemctl start mysql
If that didn't fix it
Run 'sudo mysqld --print-defaults' and compare the socket path shown with the one in the error message.
When to see a technician
Contact a database administrator if the server still will not start after checking the error log.
Quick answers
- What does ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) mean?
- The MySQL command-line client cannot reach the database server on the same machine because the expected socket file is missing. This usually means the MySQL server process is not running or failed to start.
- What causes ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)?
- MySQL server service is stopped or crashed. (most likely) Socket file path in MySQL config does not match the actual location. (possible) Permission or ownership problem on the /var/run/mysqld directory. (less likely)
- How do I fix ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)?
- Try these in order, safest first: 1. Check whether the MySQL server is running. 2. Check the MySQL error log for startup problems. 3. Start the MySQL server if it is not active.
- What if that didn't fix it?
- Run 'sudo mysqld --print-defaults' and compare the socket path shown with the one in the error message.
- When should I see a technician?
- Contact a database administrator if the server still will not start after checking the error log.
Related errors
codepermission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sockcodedocker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?codeERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versioncodeError: Hydration failed because the initial UI does not match what was rendered on the servercodessl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer cercodeerror: Your local changes to the following files would be overwritten by merge: Please commit your changes or stash them