Error Establishing a Database Connection

Critical Frequency: Common
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

  1. Wrong database credentials in wp-config.php (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST)
  2. MySQL/MariaDB service is down or unresponsive
  3. Database server is overloaded (too many connections)
  4. Corrupted database tables
  5. DB_HOST changed after server migration (localhost vs 127.0.0.1 vs socket)

How to Fix It

  1. Verify credentials: Open wp-config.php and check DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST match your hosting panel
  2. Test the database connection: Run mysql -u DB_USER -p DB_NAME from SSH to verify credentials work
  3. Check if MySQL is running: systemctl status mysql or systemctl status mariadb
  4. Repair the database: Add define('WP_ALLOW_REPAIR', true); to wp-config.php, then visit /wp-admin/maint/repair.php
  5. Check DB_HOST: Try 'localhost', '127.0.0.1', or your host's specific database server address
  6. Contact your host if the database server is down u2014 this may be a server-side issue

Frequently Asked Questions

Why does WordPress say 'Error establishing a database connection'?
WordPress can't connect to MySQL. This is usually because the database credentials in wp-config.php are wrong, or the MySQL service is down.
Can a database connection error corrupt my data?
No. This error means WordPress can't reach the database u2014 it doesn't mean your data is lost. Once the connection is restored, everything will work normally.
Get WordPress Performance Tips

Plugin reviews, speed optimization guides, and error debugging — straight to your inbox.

No spam. Unsubscribe anytime. We respect your privacy.