"Error Establishing a Database Connection" in WordPress: Causes and Fixes
“Error establishing a database connection” means WordPress cannot talk to the database that holds your content. The usual causes are incorrect login details in the configuration file, a database server that is down or overloaded, or a corrupted database.
What the error means
WordPress stores pages, posts, settings and users in a MySQL or MariaDB database. Every time someone loads your website, WordPress asks that database for information. If the request fails, WordPress cannot build the page, so it shows this message instead. The content is normally still safe. The connection to it is what has failed.
Common causes
| Cause | How it happens |
|---|---|
| Wrong database credentials | The name, username, password or host in wp-config.php no longer matches the database |
| Database server down | The host’s database service has stopped or is restarting |
| Server overload | Traffic or a heavy plugin exhausts database connections |
| Corrupted tables | A crash or interrupted update damages database tables |
| Migration problems | The site was moved and settings were not updated |
| Hacked configuration | Credentials or files were changed without permission |
Not sure what is going on with your website?
Tell us what you are seeing and we will outline the next step before any chargeable work.
Is it the front end, the dashboard or both?
If the message appears on your public pages but the admin area shows a different message, such as one asking you to repair the database, the tables may be damaged. If both show the same connection message, the problem is more likely credentials or the database server itself. Note which applies when you ask for help.
What to check first
- Whether your host has any reported database or server issue
- Whether anything changed recently, such as a migration, a password change or a hosting plan change
- Whether other websites on the same hosting account show the same error
- Whether the hosting account is active and within its limits
Why backups matter here
Repairing or restoring a database changes the data that powers your website. Before any repair, a copy of the current state should be taken, and where orders or enquiries are involved, you need to know what would be lost by restoring an older version. A restore is a last resort, not a first step.
Understanding the database in plain terms
If WordPress is the shop, the database is the filing room behind it. Every product description, page, setting and user account is kept there, and the shopfront fetches what it needs each time someone visits. The error means the shopfront cannot reach the filing room, either because the door is locked with the wrong key, the room is closed, or the filing cabinets have been damaged.
That analogy also explains why the content is usually safe. The documents have not vanished. The route to them has been interrupted.
Questions that narrow the cause quickly
- Did anything change just before it began, such as a migration, a hosting plan change or a password reset?
- Do other websites on the same hosting account show the same error?
- Does the admin area give the same message or a different one?
- Is the problem constant or does it come and go at busy times?
- Has the host sent any notices about maintenance or limits?
Recovery, with care for newer data
Repairing a database is not like restarting a computer. Changes to the database change your business data. Before any repair, take a copy of what exists, even if it appears damaged, and understand what an older backup would overwrite. For stores and sites that capture enquiries, newer orders and messages are the most valuable data on the site. A careful recovery plan protects them. If you want it handled for you, see our WordPress repair service or ask about a maintenance plan that includes verified daily backups.
The wp-config file and your credentials
WordPress stores the name of its database, the username, the password and the server address in a configuration file called wp-config.php. If any of those values stops matching the real database, the connection fails. This often happens after a migration, after a host resets passwords or when a hosting plan changes. Correcting the file is simple in principle, but the file also holds security keys and other settings, so it should be edited carefully and only after a backup is taken. Never share the contents of this file publicly or by email, because it contains the keys to your database.
Corrupted tables and automatic repair
WordPress has a built-in database repair tool that can be switched on temporarily. It can mend minor table damage, but it should be used with care: it makes changes to live data, and it must be switched off again afterwards because it can be reached without logging in while enabled. Serious corruption may need the host’s database tools or a restore from a tested backup. In every case the sensible order is the same: preserve what exists, understand the cause, repair, test and then document what was done.
What this looks like on a real business site
A café owner found their site showing the database error on the morning of a promotion. The hosting plan had been moved to a new server overnight and the database host name had changed, so the configuration no longer matched. Correcting a single value restored the site within minutes, but only after someone recognised the cause. In another case the tables had been damaged by a failed update and needed repair from a verified backup. The same message, two very different causes. That is why the first step is always to establish which kind of failure you have, using logs and the host’s status information, before changing anything.
How WP Mate approaches it
We check the configuration against the actual database, test the connection, review server and error logs and repair tables where that is appropriate, always from a confirmed recovery point. If the problem is the hosting environment, we explain your options. See WordPress repair and WordPress hosting and migration, or contact us with the details.
Want this looked after for you?
WP Mate maintenance plans cover managed updates, daily offsite backups, security scanning and 24/7 uptime monitoring.
Not sure what's wrong? Tell us and we'll outline the next step.
Services related to this guide
WordPress repair
Broken website? We investigate the cause and fix it safely.Get a Repair Quote →
Hosting and migration
Plan a safe move or review your hosting.Discuss My Hosting →
Talk to WP Mate
Not sure which service fits? Ask us and we will point you the right way.Contact us →
Related guides
Frequently asked questions
Does this error mean I have been hacked?
Not usually. Hacking is a possible cause but much less common than hosting problems or incorrect credentials. An assessment confirms which applies.
Will I lose my website content?
The content is normally still in the database. Careful repair, from a confirmed recovery point, aims to bring the connection back without losing anything.
Can my host fix this?
Sometimes, especially when the database server itself is the problem. Hosts generally do not repair WordPress-specific problems such as damaged plugin tables.
Ready to get your website sorted?
Based in Warrnambool, Victoria, helping Australian businesses online. Tell us what is happening.
Tell your mate what's going wrong.
Send us a few details and we’ll work out the next step. Please don’t include passwords or payment details.
- Australian support in plain English
- Clear scope and next steps before chargeable work
- Backup and recovery plan before live changes
