Error Establishing a Database Connection

Error message:
Error establishing a database connection‘Error establishing a database connection’ means WordPress cannot connect to your MySQL/MariaDB database. This is one of the most alarming WordPress errors because it makes your entire site inaccessible.
This error is usually caused by incorrect database credentials in wp-config.php, especially after a migration or hosting change. Less commonly, it can indicate that the database server itself is down or overloaded.
Common Causes
- Wrong database credentials in wp-config.php (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST)
- MySQL/MariaDB service is down or unresponsive
- Database server is overloaded (too many connections)
- Corrupted database tables
- DB_HOST changed after server migration (localhost vs 127.0.0.1 vs socket)
How to Fix It
- Verify credentials: Open wp-config.php and check DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST match your hosting panel
- Test the database connection: Run
mysql -u DB_USER -p DB_NAMEfrom SSH to verify credentials work - Check if MySQL is running:
systemctl status mysqlorsystemctl status mariadb - Repair the database: Add
define('WP_ALLOW_REPAIR', true);to wp-config.php, then visit/wp-admin/maint/repair.php - Check DB_HOST: Try 'localhost', '127.0.0.1', or your host's specific database server address
- Contact your host if the database server is down u2014 this may be a server-side issue
⚡
Diagnosing WordPress errors?
WP Multitool helps you find and fix performance issues, slow queries, and plugin conflicts without guesswork.
Get WordPress Performance Tips
Plugin reviews, speed optimization guides, and error debugging — straight to your inbox.
No spam. Unsubscribe anytime. We respect your privacy.