Post actualizado el día octubre 25, 2026 by DeiviSanzPlay
If you’ve seen the «Error establishing a database connection» message on your WordPress, you know it’s a real pain. Your site goes down, you can’t access the dashboard, and you break into a cold sweat. But don’t worry, this can be fixed and it’s not always your fault. I’ll tell you straight, with what I’ve learned after wrestling with this error more times than I’d like to admit.
What this error in WordPress really means
When WordPress throws that message at you, what it’s saying is that it can’t talk to its MySQL or MariaDB database. And without a database there’s nothing: no posts, no pages, no settings, no users. It’s like trying to start a car without a battery. The database connection error in WordPress is, in essence, a communication failure between the WordPress core and the server where your information lives.
Don’t confuse this with a generic 500 error. Here the problem is specific: the credentials, the database host, or the database server itself are failing. And watch out, sometimes the message doesn’t even appear as is, but instead you see a white screen or an «Error establishing a database connection» if your installation is in that language.
The most common causes (and how to detect them)
The number one cause, by far, is that someone has touched the wp-config.php file and messed it up. That file stores the database name, the user, the password, and the host. If your hosting has changed the MySQL password and you haven’t updated it, there you have your database connection error in WordPress served up.
Another frequent reason: you’ve migrated the site to a new server and haven’t updated the data. Or you’ve restored an old backup with outdated credentials. And then there’s the classic: the database server has gone down. This happens more than you think on cheap hostings. If the MySQL service is down, there’s nothing you can do from your end.
It could also be that the database is corrupted. Yes, just as it sounds. A damaged table can prevent the connection. And in rare cases, a plugin or theme with poorly written code can be hammering the database until it leaves the system without resources.
How to fix the error step by step (without making it worse)
First things first: don’t panic and don’t touch anything without making a backup. If you can access via FTP or your hosting panel, download the wp-config.php before anything else. Then check these lines:
- DB_NAME: the exact name of your database.
- DB_USER: the MySQL user.
- DB_PASSWORD: the password, without extra spaces.
- DB_HOST: usually «localhost», but some hostings use an IP or a different name.
A trick almost nobody mentions: sometimes the problem is that you’ve copied the password with a space at the end. Check that, because I’ve seen cases where the database connection error in WordPress came from a simple invisible space.
If the data is correct, try repairing the database. Add this line to wp-config.php:
define(‘WP_ALLOW_REPAIR’, true);
Then go to yoursite.com/wp-admin/maint/repair.php. There WordPress will give you the option to repair and optimize. When you’re done, remove that line immediately for security. Don’t leave it there, because anyone could run the repair.
When the problem is with the hosting
If after checking everything it’s still the same, contact your provider. Ask directly whether the MySQL server is operational. Many hostings have a public service status where you can see if there are incidents. If they tell you they’re working on it, all you can do is wait. But if they give you the runaround, consider changing hosting. A hosting that doesn’t warn you about database outages doesn’t deserve your money.
There’s a detail many people overlook: if your site has a lot of traffic and the hosting is shared, the database can run out of available connections. This generates the same database connection error in WordPress. The solution here is to upgrade your plan or move the database to a dedicated server.
Debug mode to see the real error
If none of the above works, enable debug. In wp-config.php add:
define(‘WP_DEBUG’, true);
define(‘WP_DEBUG_LOG’, true);
This will create a debug.log file in the wp-content folder. There you’ll see the exact error. It may be a plugin that’s causing the failure. Try deactivating all plugins by renaming the plugins folder via FTP. If the site comes back, reactivate them one by one until you find the culprit.
Don’t trust generic solutions that only say «update everything». That’s fine, but it won’t fix a database connection error in WordPress if the credentials are wrong. First diagnose, then act.
Prevention: what really matters
Keep WordPress, themes, and plugins updated, yes. But even more important: make automatic backups and verify that they restore properly. I’ve seen corrupt backups that are good for nothing. Try restoring in a local environment from time to time.
Also set up a downtime monitor like UptimeRobot. It will alert you on your phone if the site goes down. That way you don’t find out from an angry client. And if you can, use a hosting with real 24/7 technical support. Not one that only responds by ticket within 48 hours.
The database connection error in WordPress isn’t the end of the world, but it requires a steady hand and not going around touching files at random. With the right steps, in most cases it’s resolved in less than half an hour.



