Check the credentials, the MySQL server, the tables and the database's availability when a WordPress site can no longer connect to it. The priority is to restore a situation under control without wiping the traces useful to the diagnosis.

How do I recognise the problem?
On WordPress, a visible outage can come from the core, the theme, a plugin, PHP, the database or the server. A reliable fix isolates one variable at a time and always keeps the option of going back. Start by noting when it appeared, the most recent changes, the URLs concerned and the behaviour observed.
Note the page's HTTP status, test in a private window, and read the PHP error log along with debug.log if WordPress debugging is enabled. Note too whether the admin is still reachable: the answer points straight at the theme, a plugin or the server environment.
The message âError establishing a database connectionâ
The whole site is unavailable
An intermittent error at busy times
One signal alone does not prove the cause: âThe message âError establishing a database connectionââ can come from âIncorrect DB_NAME, DB_USER or DB_PASSWORD credentialsâ just as easily as from âThe MySQL host is down or overloadedâ. Look for at least two findings that agree before you apply a lasting fix.
Checking the four settings in wp-config.php
The message âError establishing a database connectionâ means PHP could not open a MySQL or MariaDB session with the DB_NAME, DB_USER, DB_PASSWORD and DB_HOST values. After a migration, a password change or a change of host, one of those values is usually out of date.
DB_HOST is not always localhost: some hosts use a separate database server, a specific port or a socket. Compare those values with the ones in the hosting panel, without copying them into a ticket or an unencrypted email.
When the credentials are right but the connection still fails
If the settings are correct, the database server may be down, swamped by too many simultaneous connections, or out of disk space. Intermittent errors, above all at busy hours, point at a connection limit or at a slow query locking tables.
When the admin shows a message asking you to repair the database, some tables may be corrupted. The WP_ALLOW_REPAIR constant enables the wp-admin/maint/repair.php tool: use it after backing the database up, then remove the constant at once, because that page is reachable without logging in while it is active.
Causes to check
For a WordPress database connection error, the 4 causes below are ranked from the commonest to the rarest. Test the one matching the siteâs most recent change first, one at a time.
Incorrect DB_NAME, DB_USER or DB_PASSWORD credentials
The MySQL host is down or overloaded
Corrupted tables after an abrupt shutdown
The disk quota is full, so writes fail
The recovery email WordPress sends, the Site Health report, the update history and the PHP logs often name the file and the line at fault. Start from that evidence rather than disabling plugins at random.
A good fix does not merely make the symptom disappear. It explains why the problem appeared and how to check that it does not come back.
Precautions before starting
Make a full backup of the files and the database, even if an automatic backup already exists, and write down the versions of WordPress, the theme, the plugins and PHP. Keep that copy off the server in question, and check it opens.
If the site is still taking form submissions or orders, plan a short maintenance window so nothing is written while you work.
Which cause best matches your situation?
Pick the situation closest to what you are seeing to get the first recommended action.
Want a human opinion on your exact situation?
Get a recommendationDiagnosis and fix
| Phase | Objective | A mistake to avoid |
|---|---|---|
| Observe | Reproduce it and gather the evidence | Changing several settings before you have a baseline |
| Isolate | Confirm the component or the rule responsible | Deleting files without keeping a copy |
| Fix | Apply the smallest documented change | Restoring a version that still contains the same cause |
| Validate | Test the whole journey and monitor it | Concluding from the home page loading alone |
How do I resolve the problem?
The 4 steps below tackle a WordPress database connection error from the least intrusive to the heaviest. After each change, repeat the same test; if nothing changes, go back to the previous state before moving on to the next step.
- 01
Step 1
Test the MySQL connection with the same credentials from a secure tool.
- 02
Step 2
Check the server's availability, disk space and active connections.
- 03
Step 3
Compare wp-config.php with the configuration you were given, without exposing the secrets.
- 04
Step 4
Repair only the tables flagged, then restore if the integrity still looks doubtful.
If a step changes the database or the code directly, do it on a copy first. Once the fix is in place, the first check is still this: load several pages and save a change.
Validate the resolution
Walk through the journey that was failing, then check the admin, the editor, the media library, the forms and user login. Clear the caches (plugin, server and CDN) before you conclude, or an old version can hide the result.
Validation checks
Watch the PHP log for a few days: some errors only surface when a scheduled task (WP-Cron) or a nightly backup runs.
Prevent a recurrence
Prevention has to answer the cause you identified. For a WordPress database connection error, the first measure is âMonitor the disk spaceâ; note too the signal that would have shown the incident sooner, and who is responsible for watching for it.
Monitor the disk space
Keep slow queries down
Protect wp-config.php
Test the database backups
Apply updates on a staging copy, or failing that after a verified backup, one plugin at a time. Checking the key pages after each update catches most regressions before visitors do.
Frequently asked questions
My credentials have not changed, so why the error?
The database server may be down, swamped by too many connections or out of disk space. An intermittent error at busy times points to a resource limit rather than wrong credentials.
Is my data lost?
In the vast majority of cases, no: WordPress simply cannot connect to the database, which is intact. Avoid any reinstall or import, though, until the cause is known and a recent backup has been checked.
Should you use WordPress's repair tool?
Only if a message reports corrupted tables. Back the database up first, enable WP_ALLOW_REPAIR for the duration of the repair, then remove the constant at once, because that page is reachable without logging in.
How do you check the fix will hold?
Load several pages and save a change. Check the MySQL and PHP errors once service is back. Check the backups cover both files and database. Then watch the logs, the alerts and the relevant metrics for several days.
How to resolve it
If a WordPress database connection error persists after these steps, we can pick the diagnosis up again from your logs and your access details, without acting blind on the site.
Get a diagnosisSummary with an AI
Choose your assistant: the request is prefilled where that is possible, and always copied, ready to paste if need be.

































đȘ