AI Overview
"Error establishing a database connection" means WordPress cannot reach its MySQL or MariaDB database. Check your host's status page first, then confirm DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php, repair damaged tables with the built-in tool, and restore a backup if nothing else works.
Key takeaways
- The error means WordPress cannot connect to its database, so every page including wp-admin fails.
- Check your host's status page first: an overloaded or down database server is the most common cause.
- After a migration or password change, check DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php.
- Repair damaged tables at /wp-admin/maint/repair.php with WP_ALLOW_REPAIR, then remove the setting.
- Off-site backups, page caching and monitoring keep the outage short and let you hear about it first.
Free WordPress plugin
Know which plugin update broke your site.
The free MyKavo plugin watches your site through every plugin, theme and core update, and tells you which one caused a change, before your visitors find it.
- Records every plugin, theme and WordPress update
- Checks your key pages right after each update and names the one that broke something
- One-click rollback when an update goes wrong, free
- Changes, alerts and before-and-after proof inside wp-admin
Free on WordPress.org · WordPress 6.2+ · PHP 7.4+ · The check after each update comes with every paid plan and the 14-day Pro trial
Summarize with AI
Opens the assistant in a new tab with a link to this post.
On this page
"Error establishing a database connection" is one of the most alarming WordPress errors, because it replaces your entire site with a single line of text. Every page, including wp-admin, shows the same message.
The cause is simple to describe: WordPress could not talk to its database. The fix depends on why. This guide walks through the causes in the order they are most likely, so you can get the site back quickly.
What the error means#
WordPress stores your posts, pages, settings and users in a MySQL or MariaDB database. On every page load, it connects to that database using four details from wp-config.php:
- DB_NAME, the database name
- DB_USER, the database username
- DB_PASSWORD, the password
- DB_HOST, the database server (often localhost)
If any of these is wrong, or the database server is down, overloaded or damaged, WordPress cannot load anything and shows this error.
First, check if it is only you#
Open the site in a private window and on your phone's mobile data. If the site works there, the issue may be a cached error page. If it fails everywhere, the site is down for everyone. Our guide to checking is my website down explains how to confirm it.
1. Check your host's status page#
The most common cause, especially on shared hosting, is a database server that is down or overloaded. Before changing anything, check your host's status page or support channel. If they report a database incident, there is nothing to fix on your side: wait, and the site comes back on its own.
2. Check the database credentials in wp-config.php#
If the error started right after a migration, a password change or a host change, the credentials are the likely cause.
- Open wp-config.php in the root folder of your site, through your host's file manager or SFTP.
- Find the DB_NAME, DB_USER, DB_PASSWORD and DB_HOST lines.
- In your hosting panel, open the databases section (in cPanel, MySQL Databases) and confirm that the database and user exist, that the user is assigned to that database with all privileges, and that the names match exactly, including any prefix such as account_.
- If you are unsure of the password, reset the database user's password in the hosting panel and paste the new one into wp-config.php.
DB_HOST is usually localhost, but some hosts use a separate server name or an IP and port. Your host's documentation lists the right value.
Try it on your site · free
Check your own page's meta tags
Title, description, canonical and robots - including an accidental noindex - in a few seconds.
3. Check if the database is corrupted#
If wp-admin shows a different message, such as "One or more database tables are unavailable", some tables may be damaged. WordPress has a built-in repair tool:
- Add this line to wp-config.php, above the line that says "That's all, stop editing": define( 'WP_ALLOW_REPAIR', true );
- Visit yoursite.com/wp-admin/maint/repair.php.
- Click Repair Database.
- Remove the line from wp-config.php as soon as you are done. The repair page does not require a login while it is enabled.
You can also repair tables from phpMyAdmin by selecting them and choosing Repair table.
4. Check if the database server is overloaded#
If the error comes and goes, often during traffic spikes, the database may be hitting its connection limit or running out of memory. Common triggers:
- A traffic spike or a bot crawling the site heavily.
- A plugin running slow or heavy database queries.
- Too many sites sharing the same database server.
Ask your host whether you are hitting max connections or resource limits. Adding page caching reduces database load, and blocking aggressive bots helps. If it keeps happening, the plan may simply be too small.
5. Check for a hacked or changed wp-config.php#
If nobody changed anything and the credentials in wp-config.php look different from what you expect, the file may have been modified. Compare it with a backup. Our WordPress hacked guide covers the signs and how to clean a site.
6. Restore from a backup#
If the database is badly damaged or you cannot find the cause, restore the database from a recent backup. This is the reason off-site backups matter: a backup stored on the same server can be lost along with the database. See our WordPress backup guide.
How to prevent it#
- Keep regular, off-site backups of the database, so a corrupted database costs minutes instead of days.
- Use page caching, which serves most visits without touching the database.
- Keep plugins updated and remove ones you do not use, since a badly written plugin can overload the database.
- Record your credentials safely when you migrate or change hosts.
- Monitor the site, so you find out from an alert and not from a client.
Find out the moment it happens#
When the database goes down, every page fails at once, and it often happens at night or during a traffic spike. MyKavo checks your monitored pages on a schedule and sends an alert when they start returning errors, with what each page showed before and after. For WordPress sites, the free MyKavo plugin also records the plugin, theme, core and PHP changes made before the problem, which helps you tell a hosting outage from a change on your side.
Frequently asked questions#
Frequently asked questions
What causes "Error establishing a database connection" in WordPress?
WordPress cannot connect to its MySQL or MariaDB database. The usual causes are a database server that is down or overloaded, wrong credentials in wp-config.php (often after a migration or password change), corrupted database tables, or a modified wp-config.php.
How do I fix the database connection error in WordPress?
Check your host's status page first. If the host is fine, confirm DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php match the database and user in your hosting panel. If tables are damaged, use the built-in repair tool at /wp-admin/maint/repair.php, and restore a backup if nothing else works.
Can a plugin cause the database connection error?
Not directly through a bug in most cases, but a plugin running heavy queries can overload the database server so that new connections fail. If the error appears during busy periods, look at recently added plugins and ask your host about resource limits.
Is my data lost if I see this error?
Usually not. In most cases the database is still there and WordPress just cannot reach it. Data is only at risk if the database itself is corrupted or deleted, which is why off-site backups are important.
Why does the error come and go?
An intermittent error usually means the database server is overloaded: too many connections, too little memory, or heavy traffic or bot activity. Caching, blocking aggressive bots and a larger hosting plan are the usual fixes.
How can I be alerted when my WordPress site shows this error?
Use a monitoring tool that checks your pages on a schedule. MyKavo checks monitored pages and alerts you when they start returning errors, and the free MyKavo WordPress plugin shows which changes happened before the problem.
Write for MyKavo
Know website monitoring, WordPress or SEO from real work? Pitch us a guide. You keep a byline with one link to your site. Read the guidelines
Get alerted when your site breaks. Free, no card.
Start free