WordPress "Error Establishing a Database Connection": Causes and Fixes
WordPress cannot reach its database. The most common cause is a wrong value in wp-config.php, and it is fixable in minutes.
This error means WordPress could not log in to its database. Something in the connection details is wrong, or the database server is not answering.
Cause 1: A wrong value in wp-config.php

Open wp-config.php and check these four lines against your hosting panel (Databases section):
define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_user' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'localhost' );
Compare the database name letter by letter. A single extra or missing character gives this error. Look for a hidden space inside the quotes, too.
Cause 2: Wrong password

If you changed the database user's password in the panel, put the same password in DB_PASSWORD. If you are not sure of the current one, set a new one in the panel and copy it into the file.
Cause 3: Wrong host

Most hosts use localhost, but some use 127.0.0.1 or a special address. Your host's help pages say which.
Cause 4: The database server is down or overloaded

If the details are right and the site fails only at times, the server may be busy. Check your host's status page, or contact support.
Cause 5: Damaged tables

Add this line to wp-config.php, then open yoursite.com/wp-admin/maint/repair.php:
define( 'WP_ALLOW_REPAIR', true );
Remove the line when you are done. The repair page can be used without logging in, so do not leave it enabled.
Cause 6: Wrong table prefix or missing tables

The $table_prefix in wp-config.php must match the prefix of the tables in your database.
Self-repair tool
Our upcoming Database Checker and Auto-Fix tools test these values for you.
Free checker tool
Not sure which value is wrong? Our free read-only Database Checker tests your database login and tells you which value to fix. It changes nothing.
Related guides
- Writing Clear Error Reports: Screenshots, URLs and Steps
- WordPress Tag and Date Archives Duplicate Content: Settings
- WordPress Permalinks Change: Redirect Old URLs and Avoid 404s
- Error Establishing a Database Connection in WordPress: Full Checklist