# Error establishing a database connection: fix

URL: https://wp24x7.com/fix/error-establishing-a-database-connection/
Updated: 2026-11-29
Type: page

> The WordPress message Error establishing a database connection means the site could not reach its MySQL or MariaDB database. Usual causes are wrong credentials in wp-config.php, a database server that is down or overloaded, or damaged tables. Your content is normally still there. This guide shows safe checks, repair steps and when to call.

## Key facts

- For: owners whose site shows the database connection error
- Usual causes: wrong credentials, host outage, damaged tables, full disk
- Safe first step: back up files, export the database if possible
- Data: normally still intact; the site cannot reach it
- Emergency response: 15 minutes with emergency credits; rescue is pay-only-if-fixed
- Start: call the help desk or post a project

"Error establishing a database connection" means WordPress could not talk to its MySQL or MariaDB database. **The usual causes are wrong credentials in wp-config.php, a database server that is down or full, or damaged tables. Your content is normally still there.**

> **Quick answer**
Back up first. Check the host status page, compare the four DB_ values in wp-config.php with the hosting panel, then try the built-in repair. If tables are missing, stop and call.

## What this error means

WordPress stores all posts, pages, users and settings in a database. On every request it connects using four values from `wp-config.php`. If that connection fails, WordPress cannot load anything, so it shows this single message.

## Common causes

| Cause | Typical clue | Who can fix it |
|:--|:--|:--|
| Database server down or overloaded | Error comes and goes, often at busy times | Host |
| Changed credentials | Appeared after a migration or password reset | You |
| Wrong `DB_HOST` | Some hosts need a hostname other than `localhost` | You |
| Corrupted tables | Wp-admin offers to repair the database | You, with a backup |
| User lost permissions, or database deleted | Login fails in phpMyAdmin too | Host |
| Disk or quota full | Hosting panel shows 100 percent usage | You or host |

## Safe steps to try

Back up the site files first, and export the database if your host allows it.

1. **Check whether the host has an outage.** Look at your host's status page, and check whether other sites on the same account fail too.
2. **Test wp-admin.** Visit `/wp-admin`. A different message, such as a request to repair the database, narrows the cause.
3. **Compare credentials.** Open `wp-config.php` and read these four lines:

   ```php
   define( 'DB_NAME', '...' );
   define( 'DB_USER', '...' );
   define( 'DB_PASSWORD', '...' );
   define( 'DB_HOST', '...' );
   ```

   Compare each value with the database, user and host shown in your hosting panel. Fix only a value that is clearly different, and keep a copy of the original line.
4. **Try the database login elsewhere.** Open phpMyAdmin from your hosting panel. If the user and password do not work there either, reset that database user's password in the panel, then update `DB_PASSWORD` to match.
5. **Run WordPress's built-in repair.** Add `define( 'WP_ALLOW_REPAIR', true );` to `wp-config.php`, visit `/wp-admin/maint/repair.php`, and choose repair. That page does not require login, so remove the line from `wp-config.php` straight afterwards.
6. **Check disk and quota** in the hosting panel, and clear space if the account is full.

_Credentials, host, then tables: check them in that order_

## How to tell which cause you have

Open `/wp-admin` and compare it with the front end. If wp-admin shows a different message about repairing the database, the connection works and a table needs repair. If both show the same connection error, the credentials, the host name or the server are at fault. If the error appears and disappears, the database server is struggling, which points at traffic spikes, a runaway plugin or a hosting limit rather than a wrong password.

Ask your host two direct questions: is the database server up, and has anything changed on your account, such as a password reset, a plan change or a migration? Hosts can often see connection-limit errors in their own logs, which settles the question quickly. If you recently moved hosts, assume the credentials differ until proven otherwise, because database names and users often carry a host-specific prefix.

> **Remove the repair line**
The repair page needs no login. Delete `WP_ALLOW_REPAIR` from wp-config.php as soon as you have finished, and never leave it in place.

## What not to do

Do not change the table prefix in `wp-config.php` unless you know the tables were renamed. Do not drop tables to start fresh. Do not leave `WP_ALLOW_REPAIR` in the file after running repair, because the repair page requires no login. Do not paste your database password into forums or chat tools.

## When to stop and call someone

Stop if the credentials are correct but the connection still fails, if the repair reports errors it cannot fix, if tables are missing, or if the host says the database was removed. Do not delete `wp-config.php` or reinstall WordPress over a live site; that can leave you with a fresh empty database and your real one orphaned.

## How we fix it

Through [WordPress emergency support](/wordpress-emergency-support) we respond within 15 minutes with emergency credits, and rescue is pay-only-if-fixed. We verify credentials, repair tables, and when needed recover from a backup using [backup and restore](/wordpress-backup-and-restore). If you need a project-sized recovery, [post it here](/post-project).

## What does a database error look like on a real site?

Suppose a small shop moves host over a weekend, and on Monday every page shows the connection message. The database name and user on the new host both carry a prefix the old host did not use, but `wp-config.php` was copied unchanged. The fix is to correct two lines, `DB_NAME` and `DB_USER`, to the exact values shown in the new hosting panel. Nothing was lost; the site only needed to be told where its data now lived. Compare that with an intermittent error during a sale, where credentials are correct and the cause is too many simultaneous connections, which needs the host or a developer rather than a settings change.

## How do I confirm the database itself is healthy?

1. Open phpMyAdmin from the hosting panel and confirm you can see the tables, with the prefix your `wp-config.php` expects (`$table_prefix`).
2. Check that the `wp_options` table, or the same table with your prefix, is present and has rows.
3. Check the size of the database against any limit on the plan.
4. Look in the panel for connection-limit or resource-usage warnings.
5. Test the same database login from phpMyAdmin; if that works, the problem lies in `wp-config.php`, not the database.

## What are the typical host-side fixes?

Hosts can restart the database service, raise a connection limit, restore a deleted database from their own backup, or reset a user's permissions. These are things you cannot do yourself on shared hosting, and asking for them clearly saves hours. A good request reads, "The site at this address shows a database connection error since this time. Credentials match the panel. Please check database service status and connection-limit logs."

## Which fix fits which symptom?

| Symptom | Likely fix |
|:--|:--|
| Wp-admin shows a repair message | Run the built-in repair after a backup |
| Both front end and admin show the same error | Check credentials and `DB_HOST` |
| Error is intermittent | Ask the host about connection limits and load |
| Began right after a move | Use the new host's exact database name and user |
| Tables missing | Restore from backup, see [backup and restore](/wordpress-backup-and-restore) |

## How do I prevent this?

- Keep a tested off-site backup, including the database; see [backup and restore](/wordpress-backup-and-restore).
- Monitor uptime so you learn of outages before customers do.
- Avoid heavy plugins on cheap shared hosting, and plan hosting for traffic peaks.
- Write down database details when you change host.
- Keep a copy of `wp-config.php` outside the web folder, minus any secrets you do not need to store.

## Is repairing tables safe?

The built-in repair runs standard repair commands on the tables WordPress knows about. It is usually safe, but it cannot recover data that is already gone, so a backup beforehand is essential. If repair reports a table it cannot fix, stop and restore from a backup rather than repeating it.

**Site down right now?**
A person reads it, any hour. Emergency Rescue is pay-only-if-fixed.
[Call the help desk](tel:+18043754450)
[Post a project](/post-project)

## Frequently asked questions

### Is my data deleted?

Usually not. The message means WordPress could not connect, not that the data is gone. The most common causes are wrong credentials or a database server that is down or overloaded.

### Why does it work on some page loads and fail on others?

An intermittent error often means the database server is overloaded or hitting its connection limit. That is a hosting or traffic issue rather than a settings mistake.

### Can I see this error only in wp-admin?

Sometimes. WordPress shows a separate message about a corrupted database when it can connect but the tables need repair.

### Do I need a backup before touching anything?

Yes. Back up files and, if you can reach it, export the database before changing settings or running repair.

### What does Error establishing a database connection mean?

WordPress could not talk to its MySQL or MariaDB database. It connects on every request using four values from wp-config.php, and when that fails it shows this one message instead of loading anything.

### Did my host delete my database?

Usually not, but it can happen. If your tables are missing in phpMyAdmin or the host says the database was removed, stop and ask the host to restore from their backup. Do not reinstall WordPress over the live site.

### Why did the error appear right after I changed hosts?

Database names and users often carry a host-specific prefix. If wp-config.php was copied unchanged, DB_NAME and DB_USER may not match the new hosting panel. Correct them to the exact values the new host shows.

### Is it safe to run the WordPress repair page?

It is usually safe and runs standard repair commands on tables WordPress knows about. Take a backup first, and remove WP_ALLOW_REPAIR from wp-config.php straight afterwards because the repair page requires no login.

### What should I ask my host?

Ask whether the database service is up, whether any connection-limit errors appear in their logs, and whether anything changed on your account such as a password reset, plan change or migration. Say the exact time the error began.

### Can a full disk cause this error?

Yes. If the hosting account is out of disk space or quota, the database may fail to write or start. Check usage in the hosting panel and clear space, then test again.

### Should I change the table prefix in wp-config.php?

No, unless you know the tables were renamed. The prefix must match the tables in the database, otherwise WordPress looks for tables that do not exist and behaves as if the site were empty.

### How can I prevent this error?

Keep a tested off-site backup including the database, monitor uptime, avoid heavy plugins on weak shared hosting, and write down database details when you change host. Monitoring tells you about outages before customers do.

### Can I fix this without FTP or SSH access?

Often yes for credentials: the hosting panel shows the database name, user and host, and phpMyAdmin tests the login. Editing wp-config.php does need file access, so use the host's file manager or ask support.

### When should I stop and call someone?

Stop if the credentials are correct but the connection fails, repair reports errors it cannot fix, tables are missing or the host says the database was removed. Emergency support responds in 15 minutes and rescue is pay-only-if-fixed.
