“Error establishing a database connection” means WordPress can’t talk to the database that stores your pages, products and settings. The usual causes are wrong login details in wp-config.php, a database server that’s down or overloaded, or a damaged database table. Your content is normally still there. You just can’t reach it until the connection works again.
Key takeaways
- WordPress needs four details to reach its database: name, username, password and host.
- If the message appears after a migration or password change, the login details are the first suspect.
- If it appears suddenly with no changes, the database server may be down or overloaded. Ask your host.
- WordPress has a built-in repair tool for damaged tables.
- Back up the database before you repair anything.
What does “Error establishing a database connection” mean?
A WordPress site has two halves. The files hold the code, and a MySQL or MariaDB database holds the content. Every time someone loads a page, WordPress logs in to the database to fetch it. If that login fails, WordPress shows this message instead of your page.
It looks alarming because the whole site disappears at once, including the admin area. The good news is that the database itself is rarely lost.
What causes the database connection error?
| Cause | Typical clue |
|---|---|
| Wrong database details | Started right after a migration, a host change or a password reset |
| Database server down | Started suddenly; other sites on the same host are down too |
| Server overloaded | Comes and goes, often during busy periods or a traffic spike |
| Damaged tables | The admin area says one or more tables are unavailable |
| Damaged files or malware | Unexpected changes to wp-config.php or new, odd files |

How do I fix it, step by step?
1. Check whether the admin area shows something different
Visit yoursite.com.au/wp-admin. If you see “One or more database tables are unavailable”, the connection works but some tables are damaged. Jump to step 4. If you see the same error, keep going.
2. Check the details in wp-config.php
Open wp-config.php in your site’s main folder using your host’s file manager or SFTP. Find these four lines:
define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'database_user' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );
Compare each value with the database details in your hosting panel. A single wrong character breaks the login. After a move to a new host, DB_HOST is a common culprit. Some hosts use a separate database server address instead of localhost. The wp-config guide explains each setting.
Never paste these details into an email, chat or support forum. Treat them like a bank password.
3. Ask whether the database server is running
If the details are right, contact your host. Ask whether the database service is up and whether your account hit a connection or resource limit. On cheap shared plans, one busy neighbour can starve everyone else of database connections.
4. Repair damaged tables
WordPress includes a repair tool. Add this line to wp-config.php:
define( 'WP_ALLOW_REPAIR', true );
Then visit yoursite.com.au/wp-admin/maint/repair.php and choose “Repair Database”. Remove the line as soon as you finish, because the repair page doesn’t need a login while it’s switched on.
5. Restore from a backup
If the tables can’t be repaired, restore the most recent clean database backup. This is where an off-site backup, kept away from your hosting account, earns its keep.
Could this be a hack?
Sometimes. Attackers who reach your files may change wp-config.php, or load the database so heavily that it falls over. Sucuri found malicious admin users in 55% of infected databases it cleaned in 2023. Check for:
- New admin users you don’t recognise.
- Odd PHP files in your uploads folder.
- A
wp-config.phpthat changed when nobody touched it.
If you spot any of these, treat it as a security incident. Change the database password, then get a proper clean-up.

How do I stop it happening again?
- Use hosting with enough resources for your traffic, so the database isn’t starved.
- Keep off-site backups of the database and test that they restore. Shops and booking sites need them more often than brochure sites.
- Monitor uptime, so you know within minutes, not when a customer tells you.
- Clean up the database now and then. Old revisions and expired data slow it down.
If the site shows “There has been a critical error” instead, see our guide to the critical error message. A blank page with “500” in the browser tab is covered in our 500 internal server error fix. For a shop whose checkout fails as well, our emergency WordPress repair guide goes further.
When you’d rather hand it over, our fast WordPress repairs team takes it from here, and our website support line is answered by real people in Australia. Ongoing care is part of our website maintenance plans.
Frequently asked questions
Have I lost my website?
Probably not. The error means WordPress can’t reach the database, not that the database is gone. Once the connection works, the site usually returns unchanged.
Why did this start after I moved hosts?
The new host has a different database name, user, password or server address. Update all four in wp-config.php to match the new hosting panel.
Why does the error come and go?
That usually means the database server is overloaded or hitting a connection limit. It’s a hosting resource problem, so talk to your host or consider a bigger plan.
Is the WordPress repair tool safe?
It’s built into WordPress and safe to use, but back up first. Remove the WP_ALLOW_REPAIR line straight after, because the page is public while it’s on.
Can a plugin cause this error?
Rarely on its own. A badly written plugin can overload the database with queries, though. If the error coincides with a new plugin, test with it switched off.
Sources
- Editing wp-config.php, WordPress Developer Resources
- Common WordPress errors, WordPress Developer Resources
- 2023 Hacked Website and Malware Threat Report, Sucuri, June 2024


