“Error establishing a database connection” means WordPress couldn’t reach the database where all your content lives. Your posts, pages, and settings are stored there, and when WordPress can’t connect, it has nothing to show, so the whole site goes down at once. It looks scary, but the causes are surprisingly predictable, and your content is usually completely intact.
What causes the database connection error?
There are really only four suspects: wrong database credentials in your wp-config.php file, a database server that’s down or overloaded at your host, a corrupted database, or a corrupted WordPress installation. Something changed right before the error appeared, whether that was a migration, a hosting change, a plugin install, or a traffic spike, and that change usually points to which suspect it is.
Step 1: Check whether it’s your host
Before touching any files, check your hosting provider’s status page or open a quick support chat. On shared hosting, database servers get overloaded, and the error clears on its own when the load drops. If your host confirms a server issue, your work is done. Just wait it out.
Step 2: Verify your database credentials
Open wp-config.php in your site’s root folder and find the four lines defining DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. These must exactly match the database name, username, and password shown in your hosting control panel’s database section. This is the number one cause after a site migration, because credentials that worked on the old server don’t exist on the new one. Correct any mismatch, save, and reload your site.
Step 3: Repair the database
If credentials check out, the database itself may be corrupted, which can happen after a server crash or a failed update. WordPress has a built-in repair tool: add define(‘WP_ALLOW_REPAIR’, true); to wp-config.php, then visit yoursite.com/wp-admin/maint/repair.php and click “Repair Database.” Important: remove that line from wp-config.php as soon as you’re done, because the repair page is accessible to anyone while it’s enabled.
Step 4: If nothing works, protect your data first
If the error persists, stop before trying more aggressive fixes. At this point the priority is your data. Export a backup of the database through your hosting control panel if you can, and avoid any “reinstall WordPress” buttons until a backup exists. Database problems are one area where a wrong move can cause real, permanent loss.
Frequently asked questions
Almost never. The error means WordPress could not reach the database, not that the database is gone. In most cases the data is sitting there intact, and the problem is wrong credentials, an overloaded server, or corruption the built-in repair tool can fix. Actual data loss is rare and usually comes from risky fixes attempted without a backup, so export a database backup before trying anything aggressive.
Sometimes. If the database server itself is down or overloaded, that is squarely your host’s problem, and their support team can confirm and resolve it. If the cause is wrong credentials in wp-config.php after a migration, or a corrupted database, hosts vary widely in how much they will help. That middle ground is where a WordPress specialist earns their keep.
The usual suspects are a server crash or power interruption during a write, a failed update, running out of disk space, and buggy plugins writing bad data. Sites on crowded shared hosting see it more often. Regular backups and the built-in WordPress repair tool handle most cases, and persistent corruption is a sign to involve your host or a professional.
Get it fixed without the risk
Database errors sit right at the edge of what most site owners should attempt on their own, and there’s no shame in handing this one off. We diagnose and repair database connection errors regularly, always with your data backed up before we start. Visit our WordPress troubleshooting and repair page or contact us and we’ll get your site reconnected.

