Table of contents10
Seeing “Error establishing a database connection” means WordPress cannot reach its database. The usual causes are wrong database details in wp-config.php, a database server that is down, crashed tables, or a host that has run out of connections. Work through the checks below in order, starting with the one that takes a minute.
What you will be able to do
By the end of this guide, you will be able to:
- Tell whether the problem is your login details, the database server, or your tables.
- Fix the cause yourself, without losing any content.
- Recognise when the problem is your host’s connection limit.
- Know exactly what to ask your host when you need help.
What this error means
WordPress stores every post, page, comment and setting in a database, and it reads that database on every page load. When it cannot connect, it cannot build any page at all, so it shows this error instead of your site. The error itself does not delete anything: your content is stored in the database, and the site simply cannot reach it right now. The error can also look different in wp-admin: if the connection itself works but a table is damaged, wp-admin says “One or more database tables are unavailable” instead. The two messages point at two different causes, and the table below tells them apart. If your site shows a blank page rather than this error, the cause is different — see our guide to the WordPress White Screen of Death.
The four causes, at a glance
| Cause | What you see | Fix |
|---|---|---|
Wrong database details in wp-config.php |
The error on every page, including wp-admin. Error 1045 (access denied) may appear in your logs. | Correct DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php. |
| Database server down or unreachable | The error on every page, sometimes with the whole site unreachable. | Check the server status with your host, then wait for it to return or ask the host to restart it. |
| Crashed database tables | wp-admin says “One or more database tables are unavailable.” | Add WP_ALLOW_REPAIR to wp-config.php, open /wp-admin/maint/repair.php, repair the tables, then remove the WP_ALLOW_REPAIR line. |
| Hosting connection limit reached | Error 1040 (too many connections), or the error comes and goes when the site is busy. | Reduce simultaneous connections, or ask your host to raise the limit. |
Step-by-step: diagnose the error
Work through these steps in order. Stop as soon as the site loads again.
- Back up
wp-config.phpbefore you change anything. If you can, back up the whole site too — our comparison of manual backups vs backup plugins explains the two ways to do it. - Load your site’s front page and wp-admin. If both show the error, the problem is the database connection itself. If wp-admin instead says “One or more database tables are unavailable”, skip to step 6.
- Open
wp-config.phpand check the four database details against the ones your host gave you:DB_NAME,DB_USER,DB_PASSWORDandDB_HOST. Look for a typo, an extra space, or details copied from a different site. If you are unsure how the file should look, read our guide to securing wp-config.php. - If a detail is wrong, correct it, save the file, and reload the site. If the site loads, you are done — and it is worth clearing your cache so you see the fixed site rather than a stored error page: see how to clear WordPress cache.
- If the details are right, the database server itself may be down. Check your host’s status page, or ask the host whether the database server is running. There is nothing to fix in WordPress while the server is down.
- If wp-admin reports unavailable tables, add the line
define('WP_ALLOW_REPAIR', true);towp-config.php, openyoursite.com/wp-admin/maint/repair.phpin your browser, and repair the tables. Then remove theWP_ALLOW_REPAIRline fromwp-config.phpstraight away. - If the error comes and goes, or you see error 1040, the host has run out of database connections. Ask your host about the connection limit for your plan. Whether that limit is generous depends on your hosting: see WordPress.com vs self-hosted for how the two kinds of hosting differ.
- If your host asks you to test the connection, use a small test file — and delete the file immediately afterwards.
If the site loads again but a visitor still sees the error, a cached copy of the error page may be showing — clear the cache, and if the problem keeps returning, read why caching breaks your WordPress site. If the error only appears when the site is busy, the server is struggling under load — see how to reduce server response time.
Frequently asked questions
Will I lose my posts and pages?
No. The error itself does not delete anything: your content is stored in the database, and the site simply cannot reach it. Once the connection works again, your posts and pages reappear. If a table is crashed, repair it first, and do not delete anything from the database by hand.
Can a plugin cause this error?
Not in the usual sense: a plugin does not change your database login details. Work through the four causes above first. If the error only appears when the site is busy, ask your host about the connection limit rather than blaming a single plugin.
Does this error mean my site was hacked?
Not by itself. This error is a connection problem, and the four causes in this guide are all ordinary ones: wrong details, a server that is down, crashed tables, or a connection limit. If you also find content changed or files you do not recognise, ask your host to check the site.
What if the error comes and goes?
That points to the connection limit: the site works while connections are free and fails when they run out. The fix is on the hosting side — ask your host about the limit for your plan, and consider whether your site needs more headroom at busy times.
Should I edit wp-config.php myself?
Yes, if you are comfortable editing a file — but back it up first, and change only the four database details. If you are not comfortable, ask your host to check the file for you.
Fixed it? Keep the momentum: the next error worth knowing is maintenance mode — read what to do when WordPress gets stuck in maintenance mode.









