“Error establishing a database connection” means WordPress cannot reach its database, usually from wrong credentials in wp-config.php, an overloaded database server, or corrupted tables. Check the database name, user, password, and host in wp-config.php first, then confirm the database server is running and repair the tables if needed.
The “Error establishing a database connection” message means WordPress can’t talk to its database, so it can’t load a single page. The most common cause is wrong database credentials in your wp-config.php file, usually after a migration or a host change. Less often, the database server is down or overloaded, or the database itself is corrupted. Here’s how to find which one it is and fix it, fastest cause first.
We fix this one for agencies more often than almost any other WordPress error, so the order below is the order we actually work through it, not a generic checklist.
What causes the error
WordPress stores everything (posts, settings, users) in a MySQL database. To load a page it connects using four details in wp-config.php. The error appears when that connection fails, which happens for one of four reasons:
- Wrong database credentials in
wp-config.php, the number-one cause, almost always after a site move or a host change. - The database server is down or overloaded, common on shared hosting during a traffic spike.
- A corrupted database, often after a failed update or plugin.
- Corrupted WordPress core files.
How to fix it
1. Check your database credentials (fixes most cases)
Open wp-config.php in your site’s root folder over FTP or your host’s file manager, and find these four lines:
define( 'DB_NAME', 'your_database_name' ); define( 'DB_USER', 'your_database_user' ); define( 'DB_PASSWORD', 'your_database_password' ); define( 'DB_HOST', 'localhost' );
Now confirm each value against your host. Log in to your hosting panel, open the database section (often phpMyAdmin), and check the real database name, user, and host. If your host moved servers or you migrated the site, any of these can be wrong, and a single wrong character breaks the connection. The password is the usual culprit. Update the file, save, and reload your site.
2. Check whether the database server is down
If the credentials are right, the database server itself may be down or out of resources. If you run other sites on the same host, check whether they’re up too. If everything on that server is down, it’s the host, not you, so open a ticket and ask them to confirm the MySQL service is running and you haven’t hit a connection limit. On shared hosting, a traffic spike or a heavy plugin can exhaust your allowed database connections.
3. Repair a corrupted database
WordPress has a built-in repair tool. Add this line to wp-config.php, just above the line that says “That’s all, stop editing”:
define( 'WP_ALLOW_REPAIR', true );
Then visit yoursite.com/wp-admin/maint/repair.php in your browser and click “Repair Database” (or “Repair and Optimize”). When it finishes, remove that line from wp-config.php immediately, because that page is accessible to anyone while the line is in place. WordPress documents this tool in its common errors guide.
4. Re-upload fresh core files
If none of the above works, corrupted core files are the last common cause. Download a fresh copy of WordPress, and re-upload only the wp-admin and wp-includes folders over FTP, overwriting the existing ones. This replaces the engine without touching your content, themes, or plugins.
When to stop and get help
If you’ve checked the credentials, confirmed the server is up, run the repair, and it’s still down, the problem is usually deeper: a corrupted table the repair tool can’t fix, a host-level limit, or a database that needs restoring from a backup. On a live client site, that’s not the moment to experiment. This is one of the errors our white-label WordPress team handles quietly under your brand, so your client sees a working site and never knows there was a fire. It also sits high on our list of common WordPress problems worth knowing how to diagnose, like the 500 internal server error.
- The error means WordPress cannot reach its database; start by checking the database name, user, password, and host in wp-config.php.
- Wrong credentials are the most common cause, often right after a host migration or a password change.
- If credentials are correct, the database server may be down or overloaded, or the tables may be corrupted (use WP_ALLOW_REPAIR).
- Back up the database before editing anything, and ask your host to confirm the database server is actually running.
Frequently asked questions
If you have worked through these checks and the database error will not clear, you do not have to keep wrestling with it. Send us the site and a senior developer will find the real cause, fix it on a safe copy, and hand it back working, usually within hours.
What does “error establishing a database connection” mean?
It means WordPress can’t connect to its MySQL database, so it can’t load any page. The connection uses four credentials in your wp-config.php file. The error means one of them is wrong, or the database server is down, overloaded, or corrupted. The most common cause by far is incorrect credentials after a migration or host change.
How do I fix the database connection error without cPanel?
You only need FTP or a file manager. Open wp-config.php and verify the four database credentials against your host’s database settings, since wrong credentials cause most of these errors. If those are right, use the built-in repair tool by adding the WP_ALLOW_REPAIR line and visiting yoursite.com/wp-admin/maint/repair.php, then removing the line afterward.
Is the database connection error serious?
It takes your whole site offline, so it’s urgent, but it’s usually not data loss. In most cases the data is intact and the connection is simply failing because of wrong credentials or a host issue. Fix the connection and the site returns as it was. The exception is a genuinely corrupted database, which is why keeping recent backups matters.
Why did the error appear after migrating my site?
Because the database name, user, password, or host on the new server is almost always different from the old one, and the wp-config.php file still points at the old details. Update the four credentials in wp-config.php to match the new host’s database, and the connection works again. DB_HOST in particular is often something other than “localhost” on a new host.
How do I prevent it from happening again?
Keep recent off-site backups, update plugins and core on staging before production, and avoid pushing a host to its connection limits with heavy plugins on cheap shared hosting. For client sites, a maintenance plan that monitors uptime catches a database connection failure the moment it happens instead of when the client calls.
Stuck on a client’s site and need it fixed now? You can send us the details and we’ll get it back online under your brand.
Get a free consultation and a fixed quote, usually within one business day, delivered under your agency's brand.