ERROR 2002 (HY000): Can't connect to local MySQL server
ERROR 2002 (HY000): Can't connect to local MySQL server
DodaTech
2 min read
MySQL ERROR 2002 (HY000) means the client cannot reach the MySQL server through the expected socket or port. This typically points to the MySQL service not running, a wrong socket path, or a missing installation.
What It Means
The mysql client tried to connect to the local server via /var/run/mysqld/mysqld.sock (Unix socket) or 127.0.0.1:3306 (TCP) but no process was listening at that address.
Why It Happens
- MySQL service is stopped or crashed.
- The socket file was deleted or moved.
- MySQL server is not installed.
- The server is listening on a different port or bound to a different interface.
- Disk space is full, preventing the socket file from being created.
How to Fix It
1. Check if MySQL is running
sudo systemctl status mysqlIf it shows inactive (dead), start the service:
sudo systemctl start mysql
sudo systemctl enable mysql2. Check the socket file
Verify the default socket exists:
ls -la /var/run/mysqld/mysqld.sockIf missing, find the correct socket:
mysqladmin --socket=/tmp/mysql.sock pingOr configure the socket path in /etc/mysql/my.cnf:
[client]
socket = /var/run/mysqld/mysqld.sock
[mysqld]
socket = /var/run/mysqld/mysqld.sock3. Force TCP connection instead of socket
mysql -h 127.0.0.1 -P 3306 -u root -p4. Reinstall MySQL if missing
sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installation5. Check for disk space issues
df -hIf /var is full, free up space and restart MySQL.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro