“Error establishing a database connection” means WordPress could not log in to its MySQL or MariaDB database, so it cannot load any content. In most cases the database is still there and the fix is quick: correct the login details in wp-config.php, wait for or restart an overloaded database server, or repair damaged tables. Only in a smaller number of cases has the database itself been deleted or lost, and then the job changes from fixing a connection to recovering the site from backups or archives.
This guide helps you work out which situation you are in, fix the common causes safely, and decide what to do if the database is really gone. Work through the steps in order and change one thing at a time, so you know what solved it.
What the error establishing a database connection actually means
Every WordPress page is built on request. WordPress reads the database name, user, password and host from the wp-config.php file, connects to the database server, and pulls the posts, settings and menus it needs. If that connection fails at any point, WordPress stops and shows the error instead of the page.
That gives four broad causes:
Need this done for you?
Wayback Restore rebuilds lost websites by hand from Wayback Machine snapshots. WordPress restoration ($79) starts at a fixed per-site price, with a free archive check before you pay.
Check what can be restored (free) · Request a free archive review
- Wrong connection details. The database name, username, password or host in wp-config.php no longer match what the server expects. This is very common after a migration, a host change or a password reset.
- The database server is down or overloaded. The details are right, but the server is not answering, because of a host outage, a traffic spike or a resource limit on shared hosting.
- Damaged tables. The server answers, but key WordPress tables are corrupted, often after a crash, a full disk or a failed update.
- The database is missing. It was deleted by mistake, removed when a hosting plan expired or was suspended, or lost in a failed migration.
The first three are repairs. The fourth is a recovery problem, and it is worth ruling out early so you do not spend hours changing settings on a database that no longer exists.
Step 1: Check whether only you see the error
Open the site in a private window and on your phone using mobile data. If the error appears everywhere, it is real. Then open /wp-admin/ as well as the homepage. If the front end shows the error but the admin area says one or more database tables are unavailable and may need repairing, the connection works and the problem is table damage, which is covered in Step 4.
Also check your host’s status page or support channel. If the host reports a database outage, the best action is to wait and avoid changing files while they fix it.
Step 2: Confirm the database still exists
Log in to your hosting control panel and open the database section (in cPanel this is MySQL Databases; other panels use similar names). Look for the database named in your wp-config.php file.
- The database is listed and has a size above zero. Good news: your content is probably still there. Continue with Step 3.
- The database is listed but tiny or empty. Open it in phpMyAdmin. If the wp_posts table (or the same table with your custom prefix) is missing or empty, treat it as lost and jump to the recovery section below.
- The database is not listed at all. It has been deleted or never moved across in a migration. Do not create a new empty database with the same name yet; first ask your host whether they can restore it from their own backups, which is often possible for a limited time.
Step 3: Fix the connection details in wp-config.php
Download a copy of wp-config.php before editing it. Then compare its four database settings with the values in your control panel:
- DB_NAME: the exact database name, including any account prefix the host adds.
- DB_USER: a database user that is assigned to that database with full privileges.
- DB_PASSWORD: the user’s current password. If you are unsure, set a new password for the database user in the control panel and paste it into the file.
- DB_HOST: often localhost, but many hosts use a separate database server name or a port number. Your host’s documentation lists the correct value.
The WordPress wp-config.php documentation describes each setting. A quick test is to log in to phpMyAdmin with the same user and password: if that fails too, the credentials are the problem, not WordPress.
Also check that the database user is still attached to the database. After a restore or migration the user sometimes exists but has lost its privileges, which produces exactly this error even though the password is right.
Step 4: Repair damaged tables
If the details are correct and the admin area reports unavailable tables, WordPress has a built-in repair tool. Add this line to wp-config.php, just above the line that says to stop editing:
define( 'WP_ALLOW_REPAIR', true );
Then visit /wp-admin/maint/repair.php and choose Repair Database. When it finishes, remove the line again straight away, because the repair page can be opened by anyone while it is enabled. Take a database export from phpMyAdmin before repairing if you can, so a failed repair does not make things worse.
Step 5: Rule out server load and resource limits
If the error comes and goes, the database server is probably struggling rather than broken. Common reasons are traffic spikes, bots hammering search or login pages, heavy plugins running large queries, or a shared hosting plan hitting its connection limit. Ask the host for database error logs, review recently added plugins, and consider caching or a larger plan. These fixes keep the site online but do not involve any data recovery. If you see a blank page instead of this message, follow our guide to fixing a WordPress white screen.
Less common causes worth checking
If the four main settings look right and the server is up, these quieter problems also produce the same message:
- Table prefix mismatch. wp-config.php contains a $table_prefix line, usually wp_. If a migration imported tables with a different prefix, for example abc_posts, WordPress connects but finds none of its tables. Compare the prefix in the file with the table names in phpMyAdmin.
- DB_HOST needs a port or socket. Some hosts and local setups expect a value such as localhost:3307 or a socket path. A plain localhost then fails even though everything else is correct.
- Connection limits. Shared plans often cap simultaneous connections per database user. Under load, new visitors get the error while others load the site normally. The host’s error log usually shows a “too many connections” entry.
- Full disk or quota. When the account runs out of space, the database server can stop writing and refuse connections. Clearing old backups and logs from the account can bring it back immediately.
- Edited or damaged wp-config.php. A stray quote, a missing semicolon or a file saved with the wrong encoding can break the settings. Compare it with your downloaded copy or the wp-config-sample.php file that ships with WordPress.
If the error establishing a database connection hides a deleted database
If Step 2 showed that the database was deleted or emptied, no setting will bring the content back, because there is nothing left to connect to. Ask your host for a database backup from before the loss and import it into a new database, then point wp-config.php at it. Check your backup plugin’s remote storage for a .sql file as well. If neither exists, see our guide on what to do when the WordPress database is lost but the files remain: your uploads, theme and plugins in wp-content are usually still on the server, and public posts and pages can be rebuilt from archived captures. Archives do not hold the database itself, user accounts, orders or form entries.
If the database vanished because the hosting plan expired or was suspended, read about a website deleted after hosting expired, since hosts often keep data for a short grace period.
Mistakes that make recovery harder
- Reinstalling WordPress over the old site. A fresh install creates new, empty tables and can overwrite the files you need for a rebuild.
- Creating a new database with the old name before asking the host about backups. Some restore tools then refuse to overwrite it, or you lose track of which copy is which.
- Restoring an old backup over a working database when only the credentials were wrong. You would replace current content with old content for no reason.
- Leaving the repair setting enabled in wp-config.php after use.
- Waiting. Host backups and grace periods expire. If the database is gone, contact the host on day one.
Quick decision table
| What you found | Likely cause | Next step |
|---|---|---|
| Host reports an outage | Server down | Wait; do not edit files |
| phpMyAdmin login fails with the wp-config details | Wrong credentials | Reset the user password, update wp-config.php |
| Admin says tables are unavailable | Corrupted tables | Export, then run the repair tool |
| Error appears only at busy times | Resource limits | Check logs, caching, plan size |
| Database missing or empty | Data loss | Host backups, plugin backups, then archive rebuild |
Need the site rebuilt?
When the connection is fixed, you are done. When the database is gone and nobody has a copy, our WordPress restoration service rebuilds the public site into a fresh WordPress install from archived captures and any surviving files, keeping the original URLs where the captures allow.
If the database was emptied or damaged rather than just disconnected, you will need to import a backup; see our guide to importing a WordPress database backup for the steps and the common import errors.
If the database error has cleared but the whole site still seems to have vanished, follow our guide for when a WordPress website disappeared; it separates hosting, domain, hack and deletion causes.
Frequently asked questions
Does this error mean my website has been deleted?
Usually not. Most cases are wrong connection details, a busy or offline database server, or damaged tables, and the content is still in the database. Check in your control panel that the database exists before assuming the worst.
Can I recover a deleted WordPress database without a backup?
Not the database itself. Ask your host first, since they may hold server-level backups you did not know about. If nobody has a copy, the public posts and pages can be rebuilt from archived captures, but private data such as users, orders and unpublished drafts cannot be recovered that way.
Why did the error start after I moved hosts?
The new host usually uses a different database name, user or host value, or the database was not imported. Compare wp-config.php with the new control panel and confirm the database contains your tables.
Is the WordPress repair tool safe to use?
It is designed for this purpose and is generally safe, but export the database first if you can, and remove the repair line from wp-config.php as soon as you finish.