PlainError

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Last checked 2026-11-16 · 3 fixes · reviewed answer

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

  1. MySQL server service is stopped or crashedmost likely
  2. Socket file path in MySQL config does not match the actual locationpossible
  3. Permission or ownership problem on the /var/run/mysqld directoryless likely

How to fix it

Safest first: SafeChanges settingsDangerous
  1. Check whether the MySQL server is runningSafe

    Run this read-only command to see the current status of the MySQL service.

    systemctl status mysql
  2. Check 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.log
  3. Start 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.
Did this fix it? Report a problem

Related errors

All Coding errors →