Black FridayCyber Monday 2026
13Days
14Hrs
16Mins
34Secs
Flat20% OFF

Our biggest sale of the year20% off the first payment on all maintenance plans. Code BF2026

Grab the deal
WordPress

“Error Establishing a Database Connection” in WordPress: Causes and Fixes

When WordPress cannot reach its database, the whole site goes down. Learn what the message means and how to check credentials, the host and tables safely.

wpallsolution Updated 7 min read

When a WordPress site shows only the words “Error establishing a database connection”, WordPress could not talk to the MySQL or MariaDB database that holds your posts, pages and settings. Without the database it cannot build a single page, so the whole site goes down, usually including the dashboard. The cause is nearly always one of three things: wrong connection details, a database server that is unavailable, or damaged tables. This guide checks them in that order.

Quick answer

First check the database details in wp-config.php (name, user, password and host) against what your hosting panel shows. If they are right, ask your host whether the database server is running or overloaded. If the front end loads but the admin says tables are unavailable, repair the tables with WordPress’s built-in repair screen, then remove the setting that enabled it. Keep a backup before you change anything.

How this guide was prepared: it is research-based. We read the WordPress source code and developer documentation listed under Sources, checked on October 23, 2026. We did not reproduce this error on a live host, so the steps are the documented order of checks, not a guarantee for every setup.

What the message means

In WordPress’s code, this message appears when the database class cannot connect. The text that goes with it says the cause is either wrong username and password information in wp-config.php or that the database server at the host name could not be contacted, and it asks three questions: are the username and password correct, is the host name correct, and is the database server running? A related message, “Error reconnecting to the database”, appears when a connection that worked was lost, for example because the server is down or under heavy load.

WordPress also lets a site owner replace this page by adding a file named db-error.php to wp-content; WordPress then answers with HTTP status 500 and shows that file. If you see a branded error page instead of the plain message, this may be the reason.

The decision tree: credentials, server or tables?

Flowchart for the WordPress error establishing a database connection: five questions about scope, recent changes, host status, credentials and table repair
Five questions point to credentials, the server or damaged tables.
  1. Site and wp-admin both show the error? Treat it as a connection problem (Step 1).
  2. Started after a move, restore or password change? Compare the details (Step 2).
  3. Other sites on the same host fail too? Contact the host (Step 3).
  4. Credentials fail outside WordPress too? Reset the database user password and update wp-config.php (Step 4).
  5. Only wp-admin reports unavailable tables? Repair them (Step 5).

Symptoms and likely causes

What you seeLikely causeStart with
Error on every page and in wp-adminWrong details, or the database server is not reachableSteps 2 and 3
Error right after moving hosts or restoring a backupThe new database name, user, password or host differsStep 2
Site works, then fails at busy timesThe database server is overloaded or hits a limitStep 3
Front end works but wp-admin says tables may need repairOne or more damaged tablesStep 5

5 steps to fix “Error establishing a database connection”

Step 1: Confirm the scope

Open the home page, an inner page and /wp-admin/. If every one shows the connection error, the connection is broken. If only /wp-admin/ complains that tables are unavailable, skip to Step 5. Check your host’s status page or notices too, in case of a known database incident.

Step 2: Compare wp-config.php with your host’s details

Open wp-config.php in your file manager or over SFTP and find DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. Compare each with the database section of your hosting panel. Typical slips are a different database name after a migration, a password changed in the panel but not in the file, a host name that is not localhost on your host, or a stray space or quote. Do not paste the file or its passwords into public chats or tickets.

Step 3: Ask whether the database server is available

If the details match, the server may be down, restarted or limited. Ask your host to check the database service and your account limits. A host can also tell you whether the problem began at a specific time, which helps you decide whether a restore or a wait is right. If you recently moved hosts, see how to move WordPress to a new host for the checks that apply to the new database.

Step 4: Test the credentials outside WordPress

Log in to the database with the same user and password through your host’s database tool, such as phpMyAdmin. If it fails there, the credentials are wrong or the user lost its rights: reset the user’s password in the hosting panel, grant the user access to the database, and put the new password in wp-config.php. With WP-CLI available, wp db check also reports whether WordPress can reach and check the database.

Step 5: Repair damaged tables, then switch repair off

If WordPress says that one or more database tables are unavailable and the database may need repair, add define( 'WP_ALLOW_REPAIR', true ); to wp-config.php and open /wp-admin/maint/repair.php. The WordPress documentation points out that this page works without logging in, because a damaged database often prevents login. That also means anyone who knows the address can use it, so remove the line as soon as you have finished. Take a backup first. If repairs do not help, restore a known good backup; see is your WordPress backup really safe.

Version and hosting differences

  • Shared hosts often use a database host name other than localhost; the panel shows the right one.
  • Cloud and managed hosts can add connection limits or separate database servers.
  • A persistent object cache can make a site look partly alive while the database is down, so test with the cache off if the behaviour is odd.

How to verify the fix

  • The home page, an inner page and the dashboard open normally.
  • You can create and save a draft post.
  • WP_ALLOW_REPAIR is no longer in wp-config.php.
  • Site Health shows no new critical issue; see WordPress Site Health.

How to prevent it from happening again

  • Keep an up to date, tested backup of the database and files.
  • Write down the database details somewhere safe when you change them.
  • Watch uptime and database errors, and keep an eye on resource limits as the site grows.
  • Make backups and restores part of a regular maintenance routine.

Frequently asked questions

Does this error mean I lost my content?

Not by itself. The content is still in the database. It just cannot be reached until the connection works again.

Why can I not even log in?

The dashboard also needs the database, so it shows the same error.

Is the repair screen safe?

It is useful but not protected by login, so enable it only while you need it and remove the setting afterwards.

Can a plugin cause this?

It can, indirectly, for example by overloading the database. Check the connection details and the server first.

Related guide: ERR_TOO_MANY_REDIRECTS in WordPress: Find the Redirect Loop

Related guide: WordPress Database Cleanup: Autoloaded Options, Transients and Revisions

What to do next

Check the details, ask your host about the server, test the credentials and repair tables only if needed. If you cannot get the site back, wpallsolution offers an emergency WordPress fix and WordPress maintenance packages. We cannot promise a result without seeing your hosting setup.

Sources and official documentation

Keep reading

More guides

Need a hand with this?

Tell us what is happening. We reply with honest next steps.

Talk to us