This is WordPress's message when it can't connect to its MySQL database. WordPress's own documentation says the usual cause is wrong database details in the wp-config.php file. The other common cause is that the database server is down or overloaded, which you'll see if the details haven't changed. Check wp-config.php first, then whether the database is running.
What's the problem
Your WordPress site (and often its admin area) shows only "Error establishing a database connection" on a white page.
Why it happens
- Wrong details in
wp-config.php: the database name, username, password or host (DB_NAME,DB_USER,DB_PASSWORD,DB_HOST) don't match. Common after moving hosts or changing the database password. - The database server is down or overloaded, often on shared hosting during busy times.
- The database is corrupted, for example after a crash.
- Too many connections from a traffic spike or a plugin.
How to fix it
- Open
wp-config.php(in your site's root folder, via your host's file manager or FTP) and compare the database settings with the ones in your hosting control panel. - If you moved hosts or changed the password, update
wp-config.phpto match. - Check the database is running in your hosting panel, or ask your host.
- If the admin area shows a different message about repairing the database, WordPress can try to repair tables: add
define( 'WP_ALLOW_REPAIR', true );towp-config.php, visit/wp-admin/maint/repair.php, then remove the line again. - If it comes and goes, the database is likely overloaded. Ask your host about connection limits, or upgrade.
What Preventionlabs checks
One click runs the full report on your domain. For this problem it shows whether your site loads, how fast, and where its redirects go; uptime checked every 5 minutes, with an email when the site goes down and when it is back. With Cloudflare connected, it also shows which pages returned server errors (5xx) to visitors, and when; recent deploys and account changes, with their times. It can't connect to your database, so the database error itself is in your host's or database provider's logs.
Run your free reportYour first report is free, no card needed. Then A$50 a month, up to 10 domains. Read-only: it never changes anything.
Sources
- WordPress: Common WordPress errorsofficial docs
If you get a page featuring the message “Error Establishing Database Connection”, this means that there is a problem with the connection to your database and there could be a number of reasons for this.
- WordPress: Common WordPress errorsofficial docs
“Error establishing a database connection” is usually caused by an error in your wp-config.php file.
- WordPress: Editing wp-config.phpofficial docs
The script can be found at {$your_site}/wp-admin/maint/repair.php .
Preventionlabs is independent and not affiliated with WordPress. Product names are used only to describe the problem.
← All of Database