WordPress websites and business systems

How to Fix “Error Establishing a Database Connection” in WordPress

The three causes of this WordPress error and how to fix each: credentials, a corrupted database, or the database server.

Chris Eggleston
Chris Eggleston WP Mantis
Updated November 14, 2026 /  
Database connection. Three causes, checked in order.

“Error establishing a database connection” means WordPress cannot talk to the database where all your content and settings live. Nothing loads, including the dashboard. Your content is almost always still there. WordPress just cannot reach it.

There are three usual causes: wrong database details in wp-config.php, a damaged database table, or a database server that is down or overloaded. This guide walks through them in the order we check them on client sites.

Quick diagnosis: when did it start?

What happened right before the error usually tells you where to look first.

What happenedMost likely causeGo to
You just moved the site or changed hostsWrong database name, user, password or hostStep 1
Someone changed a password in the hosting panelThe password in wp-config.php no longer matchesStep 1
The front end is down and the dashboard mentions tables being unavailableA corrupted tableStep 2
The error comes and goes, often at busy timesThe database server is overloadedStep 3
Nothing changed and every site on the account is downThe host has an outageCheck the host

First: is it just you?

Check your host’s status page or dashboard. If the database server is down or overloaded, every site on it shows this error and the fix is on their side. If you are on a busy shared server and see this error during traffic spikes, that is a sign you have outgrown the hosting.

If you have more than one WordPress site on the same account, load the others. All of them down points at the server. Only one down points at that site’s wp-config.php or its database.

Get the real error message

The message WordPress shows visitors is deliberately vague. The database gives a much more specific reason, and you can have WordPress write it to a log. Add these lines to wp-config.php, above the line that says “That’s all, stop editing!”:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Reload the site, then open wp-content/debug.log. Our guide to the WordPress error log covers where to find it and how to read it. Look for one of these:

Message in the logWhat it means
Access denied for userThe username or password is wrong, or the user has no rights on that database
Unknown databaseThe database name is wrong, or the database was deleted
Can't connect to MySQL server or Connection refusedThe host value is wrong, or the database server is not running
Too many connectionsThe server is overloaded
No such file or directoryThe host is set to localhost but the server expects an address or a different socket

Set WP_DEBUG back to false when you are done.

1. Check the database credentials

This is the most common cause, especially right after a migration or a password change. Open wp-config.php in your site’s root folder and find these four lines:

define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'database_user' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );

Compare each value with the database details in your hosting panel. Pay attention to:

  • DB_HOST: not always localhost. Some hosts use a separate hostname or a port, such as 127.0.0.1:3306.
  • Prefixes: on some hosts the database and user names start with your account name, like acct_wpdb.
  • The password: if you are not sure, reset the database user’s password in the hosting panel and paste the new one into wp-config.php.
  • Permissions: make sure the user is actually assigned to the database with all privileges.
  • Quotes: each value must sit inside straight single quotes. Curly quotes pasted from a document or an email break the file.

Test the credentials outside WordPress

To find out whether the problem is the credentials or WordPress itself, create a file called db-test.php in the site’s root folder with the same four values:

<?php
mysqli_report( MYSQLI_REPORT_OFF );
$link = @mysqli_connect( 'localhost', 'database_user', 'password', 'database_name' );
echo $link ? 'Connected' : 'Failed: ' . mysqli_connect_error();

Visit yoursite.com/db-test.php. “Connected” means the details are right and the problem is somewhere else. “Failed” comes with the reason. Delete the file as soon as you have your answer, because it contains your database password.

If it started right after a migration

  • The new host created a new database with its own name, user and password. The old values came over inside wp-config.php and need replacing.
  • Confirm the database import finished. Open the database in phpMyAdmin and check that tables such as wp_options and wp_posts exist and have rows.
  • If you see the WordPress install screen instead of this error, the connection works but the $table_prefix in wp-config.php does not match the tables you imported.

2. Repair the database

If the dashboard says “One or more database tables are unavailable,” a table is corrupted. Add this line to wp-config.php just above “That’s all, stop editing!”:

define( 'WP_ALLOW_REPAIR', true );

Visit yoursite.com/wp-admin/maint/repair.php and click Repair Database. Remove the line when you are done, because the repair page does not require a login. With WP-CLI, wp db repair does the same thing.

Take a backup of the database first if you can reach it through your hosting panel. A repair is normally safe, but you want a copy of the data as it is before anything changes it.

3. The database server is struggling

If the credentials are correct and the error comes and goes, the database server may be running out of connections or memory. Signs: the error appears under load, or the host’s logs show “too many connections.” Your host can confirm. Long term, caching and better hosting fix it.

Common reasons a database server gets overwhelmed:

  • No page caching. Every visit runs database queries. A cache serves most visitors a saved copy instead.
  • Bot traffic. Login attempts and aggressive crawlers can open more connections than real visitors do.
  • A slow plugin. One plugin running heavy queries on every page can hold connections open until the server runs out.
  • Noisy neighbors. On shared hosting, another customer’s busy site uses the same database server as yours.

If you run your own server

On a VPS or cloud server you are the host, so these checks are yours to do over SSH:

sudo systemctl status mysql
df -h
free -m
  • The service is stopped. Start it with sudo systemctl restart mysql. On servers running MariaDB the service is called mariadb.
  • The disk is full. The database cannot write and stops. Clear old backups and logs, then restart the service.
  • The server ran out of memory. On small servers the system stops the database to protect itself. If this repeats, the server is too small for the site. Our guide to VPS hosting for WordPress covers sizing.

If none of that works

  • Restore the most recent backup from before the error started.
  • Check that wp-config.php was not modified unexpectedly. Unknown code there can mean a hack: see what to do if your site is hacked.
  • Check that the database still exists in your hosting panel. Expired hosting accounts sometimes remove it.
  • Send your host the exact message from the log. “Access denied for user” gets a faster answer than “my site is down.”

How to keep it from happening again

  • Keep backups off the server. A backup stored on the same server as the site is no help when that server is the problem.
  • Monitor uptime. You should hear about an outage from a monitor, not from a customer. See how to know when your site is down.
  • Use page caching. It is the single biggest reduction in database load for most sites.
  • Write down database changes. If anyone resets a database password, wp-config.php has to be updated in the same sitting.
  • Match the hosting to the site. Repeated database errors under normal traffic mean the plan is too small.

Common questions

Did I lose my content?

Almost never. The error means WordPress cannot reach the database, not that the database is gone. The exceptions are a deleted database and a badly corrupted one, and a backup covers both.

Can a plugin or theme cause this error?

Not directly. A broken plugin normally causes a white screen or a critical error. A plugin can cause it indirectly by running queries heavy enough to overload the database server.

Why does the error come and go?

Wrong credentials fail every time. An error that appears and clears by itself is a server running out of connections or memory, so go to step 3.

Will this hurt my search rankings?

A short outage will not. Search engines come back and try again. A site that stays down for days, or goes down repeatedly, can lose rankings, which is another reason to monitor uptime.

Need it back online now?

Our $79 one-time fix covers it, fixed or your money back. If this keeps happening, our managed WordPress hosting puts your site on a server with resources of its own.

Chris Eggleston
Chris Eggleston
Husband. Father to 4. Grandpa to 2. Gravity Forms enthusiast. As the owner of WP Mantis, I’m on a mission to simplify the WordPress experience for site owners. I also try to bring a unique perspective to the Gravity Forms community at gravityranger.com.
Next step Not sure what your site needs next?

We will look at it properly and tell you the five things worth doing, in order, whether or not you hire us.

Affiliate links disclaimer