Why this error takes the whole site down
Every page on a WordPress site is assembled from the database on request: the posts, the menus, the settings, the user accounts, the orders. When WordPress cannot reach that database at all, there is nothing to build a page from, so it stops and prints one sentence: “Error establishing a database connection”. The home page, the blog, the shop and the login screen all show the same line.
The good news is that the content is very rarely lost. In most cases the data is sitting safely on the server and WordPress simply cannot get in. The work is in finding out which link in the chain has broken. This error is one of several that can take a site offline, and our overview of WordPress errors and how to fix them shows where it fits among the others.
The chain WordPress relies on
To connect, WordPress reads four values from wp-config.php in the site’s root folder:
DB_NAME, the name of the database;DB_USER, the database username;DB_PASSWORD, that user’s password;DB_HOST, the server the database lives on, oftenlocalhostbut sometimes a separate address your host provides.
It then knocks on the database server’s door with those details. The connection fails if any value is wrong, if the database server is not answering, if it is answering but refusing new connections, or if that user no longer has permission to use that database. Each has a different fix, which is why trying random things wastes time.
Common causes, and how each one tends to show itself
Changed or mistyped credentials
Someone reset the database password in the hosting panel, a developer edited wp-config.php, or the site was moved and the new values were never filled in. This usually starts at a clear moment you can point to. After a move between hosts it is especially common, and the post on errors that appear after a migration lists the other things that tend to go wrong at the same time.
The database server is down or overloaded
On shared hosting, the database server is used by many sites. If it crashes, restarts or is swamped, every site on it may show this error at once. A tell-tale sign is that the site comes and goes, working one minute and failing the next, often at busy times. Traffic spikes, bad bots and slow queries from a heavy plugin can all push a small database server past its limits.
Too many connections
Hosts cap how many connections one account may open. A burst of visitors, a crawler, or a plugin that opens connections and does not release them quickly can hit that cap. The site recovers on its own once the load drops, then fails again later.
Corrupted tables
A crash during a write, a full disk, or an interrupted import can damage a table. Sometimes the front end shows the connection error while /wp-admin/ shows a different message saying one or more database tables are unavailable and the database may need to be repaired. That second message is a strong hint that the credentials are fine and the data itself needs attention.
Account limits or suspension
If a hosting account has run out of disk space, gone over a resource limit or has an unpaid invoice, the host may stop the database service for it. The site files can still be served while the database refuses every request.
Tampering
Less often, credentials change because someone with unauthorised access changed them, or a malicious script has filled the database with junk. If you also see unknown admin users or spam content when the site does load, read about cleaning a hacked WordPress database before simply reconnecting things.
Checks you can do before calling anyone
First, protect what you have. Download a copy of the site files and, if the hosting panel lets you, export the database through phpMyAdmin or the host’s own backup tool. Our step-by-step piece on backing up a WordPress site covers the usual methods. If the database will not export, at least save the files, especially wp-config.php.
- Check whether it is only your site. If you have other sites on the same hosting account and they also show the error, the problem is almost certainly on the server side.
- Look at your host’s status page or recent emails. Maintenance windows, outage notices and suspension warnings explain a lot.
- Compare the credentials. Open
wp-config.phpin the file manager and compare the four values with the database and user listed in the hosting panel. A single wrong character is enough. Do not change the password in the panel unless you also update the file to match. - Try logging in to phpMyAdmin. If the host’s database tool opens your database and shows tables, the database server is alive and the data exists. That points back at the credentials or the user’s permissions.
- Check that the user is attached to the database. Many panels let you see which users are assigned to which database. A user created but never granted access to the database will fail every time.
About the built-in repair tool
WordPress includes a repair script for damaged tables. It is switched on by adding define( 'WP_ALLOW_REPAIR', true ); to wp-config.php and then visiting /wp-admin/maint/repair.php. That page works without logging in, which is exactly why the line must be removed again as soon as you are done. Only use it when the messages point to damaged tables, and only after the database has been backed up. It cannot help if the server is down or the password is wrong.
When this is not something to handle alone
Bring in help when phpMyAdmin will not connect either, when the host says everything is fine but the error continues, when tables fail to repair, or when the error keeps returning under load. Recurring failures at peak times are usually a capacity or query problem, not a broken setting. Sometimes the honest answer is that the hosting plan cannot carry the site any more, and our hosting and domain support can help you move to something steadier. Similar intermittent behaviour shows up in the gateway errors described in what 502, 503 and 504 errors mean, so it is worth ruling those out too.
If the site is completely offline right now and you do not know where to begin, the emergency page for a site that is down tells you what to send us so we can move quickly.
Our approach to a database connection failure
Message us on WhatsApp or through the contact form with a screenshot of the error and, if you know it, the name of your host. We look, tell you honestly what we think is going on and when we can start. A shop that cannot take orders is handled as urgent.
We begin by saving the files and, if it can be reached, the database, so nothing we try can make things worse. Then we work down the chain in order: credentials, user permissions, database server status, connection limits and table health. Each step either rules a cause out or confirms it, so we are not guessing.
If the fault is on the host’s side, we gather the evidence and raise it with their support in terms they cannot brush off, then confirm the fix once they act. If the tables are damaged, we repair them from a copy first and only touch the live database once the repair checks out. If credentials were changed by someone who should not have access, we treat it as a security incident and make sure that access is closed.
Once the site is back, we look at why it happened. A database that has grown heavy with old revisions, expired transients and leftover plugin tables puts extra load on the server; our notes on keeping the WordPress database lean explain that housekeeping. You get a short write-up of the cause and what we changed. If you are outside India, our team is in India and keeps IST hours, and we accept payment by PayPal or Wise.
A connection error that turns out to be part of a bigger fault in plugin or theme code moves to our bug fixing service for WordPress, and if the server is returning a generic 500 page rather than this message, see the fix for WordPress 500 errors.