WordPress «database connection» error: causes and fix
This error leaves your WordPress unreachable within seconds: neither you nor your visitors can get in. Here are the most common causes and how to fix it step by step without losing content or Google rankings.
Published on · Updated on · 9 min read

You go to your site and find a blank screen with a dry message: «Error establishing a database connection». Your WordPress won’t load, neither will the admin panel, and you don’t know if you’ve lost the content.
Take a breath: in the vast majority of cases you haven’t lost anything. This error means WordPress can’t communicate with the database where it stores everything (posts, pages, users, comments, configuration). The content is still there; the problem is the connection.
In this guide I’ll explain what it means exactly, what the most common causes are and how to fix it step by step. If your site runs on WordPress, this is one of those errors you should know about. And if you want to understand why technical maintenance is key, start with why your WordPress needs maintenance.
What the error means and why it appears
WordPress doesn’t store content in HTML files like a static site. It stores it in a MySQL or MariaDB database that lives on your server. Every time someone visits your site, WordPress makes a request to that database to retrieve the information and build the page.
When that request fails, WordPress has nowhere to get the content from and shows the error message. You could say it’s like a restaurant with the kitchen closed: the venue is open, but there’s no way to serve anything.
The causes vary widely, but nearly all boil down to three fronts: credentials, server or data corruption. Let’s look at them one by one.
The 6 most common causes
These are, in order of frequency, the reasons why this error appears:
Incorrect credentials in wp-config.php
The wp-config.php file stores the connection details:
database name, user, password and host. If someone
has changed the password from the hosting and hasn’t updated it
here, or if a space has slipped in while editing the file, WordPress
won’t be able to connect.
The database server is down
This is the most common cause when the site was working fine and suddenly stops loading. The MySQL/MariaDB service has stopped due to overload, hosting maintenance or a failure of the server itself.
User without privileges or deleted
Sometimes the database user exists, but their permissions have been revoked, they’ve expired, or they’ve been deleted by mistake from the hosting panel. WordPress can’t access even if the credentials are correctly written.
Corrupted database
If the server has crashed in the middle of a write, a plugin has performed an operation that didn’t close properly, or there’s been an abrupt shutdown, one or several tables may have been damaged. MySQL then rejects the connection.
Too many simultaneous connections
Cheap hosting with low max_connections limits blocks when it receives a lot of traffic or when a plugin opens too many connections. The database rejects new requests and WordPress shows the error.
Recently installed plugin or theme
Some badly programmed plugins modify the
wp-config.php file or overload the database with heavy
queries. If the error appears right after installing or updating
something, suspect that first.
How to fix it step by step
I suggest a logical order: from the fastest and most frequent to the most complex. Don’t skip steps; each one rules out a cause and brings you closer to the solution.
Step 1 · Check that the server is running
Before touching anything, log into your hosting panel (cPanel, Plesk, SiteGround, Raiola, etc.) and look for the databases section or the service monitor. Many panels show whether MySQL is running. If it’s stopped, start it and try again.
If you can’t access the panel, contact hosting support. In my experience, this cause accounts for more than half of the cases.
Step 2 · Check the credentials in wp-config.php
Access via FTP or the hosting file manager and open
wp-config.php at the root of your WordPress. Look for these
four lines:
| Constant | What it contains | Where to verify it |
|---|---|---|
| DB_NAME | Database name | Hosting panel → Databases |
| DB_USER | Database user | Hosting panel → MySQL users |
| DB_PASSWORD | User password | The one you set when creating the user |
| DB_HOST | Server where the database lives | Usually localhost; some hostings use a different IP |
Compare each value with what you have in the hosting. An extra space, a badly closed quote or a changed capital letter breaks the connection. If you’ve recently changed the password from the hosting, update it here too.
Tip: before editing wp-config.php,
download a copy of the original file. If something goes wrong, you can
restore it in seconds and get back to the starting point.
Step 3 · Check user and privileges in MySQL
Log into phpMyAdmin from your hosting. There you can see:
- Whether the WordPress user exists for real.
- Whether it’s assigned to the correct database.
- Whether it has all the necessary privileges (SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, etc.).
If you see that the user doesn’t exist or has lost permissions, recreate it
from the hosting panel and assign full privileges over the
WordPress database. Then update the credentials in
wp-config.php if you’ve had to generate a new password.
Step 4 · Repair the database if it’s corrupted
If the credentials and permissions are correct and the server is running, one or several tables are probably damaged. There are two ways to repair them:
Option A · From phpMyAdmin
- Select your WordPress database.
- Tick all the tables.
- In the dropdown at the bottom, choose Repair tables.
- Wait for it to finish and try to load the site.
Option B · From WordPress with WP_ALLOW_REPAIR
Add this line to your wp-config.php just before
«That’s all, stop editing!»:
define('WP_ALLOW_REPAIR', true);
Then visit:
https://yourdomain.com/wp-admin/maint/repair.php
and click Repair database. When you’re done,
remove that line from the file for security.
Step 5 · Restore a backup
If none of the above works, or if you suspect there’s been an accidental deletion or serious corruption, the fastest and safest route is to restore a recent backup.
If your hosting keeps automatic backups, you can do it from the panel itself in a few clicks. If not, you’ll need to upload the copy you have (for example, made with UpdraftPlus) and import it.
Important warning: restoring a backup takes you back to the state the site was in when the backup was made. You’ll lose the posts, comments or changes made after that date. Use it as a last resort, not as a first option.
How to prevent it from happening again
This error usually doesn’t warn you. It appears suddenly, normally at the worst moment. These three measures drastically reduce the likelihood of suffering it:
Hosting with sufficient resources
Cheap hosting with low connection, memory or CPU limits is the perfect breeding ground. If your site receives traffic or has demanding plugins, invest in hosting that can handle the load.
Automatic daily backups
Set up automatic backups, both of files and databases, and store them off the server (Google Drive, Dropbox, S3…). If something breaks, you restore and move on.
Regular WordPress maintenance
Updating WordPress, themes and plugins prevents vulnerabilities, conflicts and inherited errors. A serious WordPress maintenance plan is the best prevention.
If you also bear in mind that this type of error affects SEO (Google interprets that the site isn’t available and may reduce crawling), you’ll see that preventing them isn’t just a matter of convenience, but of ranking. Here are the most common HTTP errors and how to fix them, in case you want to complement this guide.
And if you also want to make sure your WordPress is properly configured on a technical level, review how to create robots.txt and sitemap XML correctly or take a look at the complete SEO audit in 7 steps.
SEO tip: if the error persists for hours, submit the affected URL for review in Search Console once the site is working again. This speeds up reindexing and reduces the impact on rankings. If you want to know how to do it well, take a look at the guide on how to improve CTR on Google.
Frequently asked questions
Why does the «Error establishing a database connection» message appear in WordPress?
Because WordPress can’t communicate with the MySQL or
MariaDB database where it stores all the content. The most common
causes are: incorrect credentials in wp-config.php, database
server down, user without privileges, corrupted database,
too many simultaneous connections, or a plugin/theme that has
modified the configuration.
Do I lose my site content when this error appears?
In the vast majority of cases, no. The error means WordPress can’t connect to the database, but the data is still stored on the server. If the problem is credentials, permissions or a downed server, fixing it brings everything back to normal. Only in cases of serious corruption or server loss might you need to restore a backup.
How can I prevent this error from happening again?
The three most effective measures are: hiring quality hosting with sufficient resources and monitoring, taking automatic daily backups, and keeping WordPress, themes and plugins up to date. A good WordPress maintenance plan drastically reduces the likelihood of suffering it.
Does this error affect my site’s SEO?
Yes, if it lasts over time. Google may interpret that the site isn’t available and, if the error persists for days, reduce crawl frequency or even deindex pages temporarily. What’s more, users arriving from search will see a broken site and the bounce rate will rise.
Does your WordPress throw technical errors?
I review your installation, detect database, performance and configuration issues, and leave your site stable and ready to rank.