MySQL Error 2002
MySQL Error 2002 Connection Refused (MySQL) Error
What This Error Means
MySQL Error 2002 indicates that PHP cannot connect to the MySQL server socket or TCP port. It usually means the database server is not running or the socket file is missing.
Common Causes
- MySQL service is stopped.
- Wrong socket path in `php.ini` or `wp-config.php`.
- Firewall blocking port 3306.
- Trying to connect to `localhost` when the socket is disabled.
How to Fix It (For Users)
- 1 Contact the site administrator.
For Site Owners / Developers
- Start the MySQL service (`systemctl start mysql`).
- Check if `mysql.sock` exists and matches your config.
- Try changing `localhost` to `127.0.0.1` to force TCP instead of socket.
- Check firewall rules for port 3306.
When It Is NOT Your Fault
If the hosting provider's database server is down.
Is the website actually down?
Sometimes the issue is just on your end. Check if the website is down for everyone or just you.
Check Website Status →Recommended Tool to Prevent This Error
Prevent server timeouts and resource exhaustion with scalable cloud infrastructure.