Home/Blog/WordPress Error Establishing Database Connection Fix
Fast answer

WordPress shows an error establishing a database connection when it cannot reach the database that stores site content, settings, users, and plugin data. Use this urgent triage guide to check scope, credentials, hosting status, database health, repair options, and restore paths without making the outage worse.

Last updated June 26, 2026
Written by Mark Anthony Garcia
Publishing standard Fast answer, scoped workflow, tradeoffs, edge cases, next step, and citations where needed.
Author profile Editorial policy Review policy Monetization disclosure

What the Error Establishing a Database Connection Really Means

WordPress error establishing a database connection fix guide

Error establishing a database connection means WordPress files load but cannot reach the database that stores your content. The usual causes are wrong credentials in the wp-config.php file, a crashed or overloaded database server, or corrupt tables. Fix it in order: confirm the scope, verify wp-config.php credentials, check the database server, then repair the tables.

When WordPress shows the message “error establishing a database connection,” the application files are running but cannot talk to MySQL or MariaDB. Every post, page, user, setting, and order lives in that database, so the front end and the dashboard both go blank even though nothing was actually deleted. The content is almost always safe. The job is to restore the link between WordPress and the database server.

This guide walks through the database connection error in the order an experienced WordPress engineer would work it: scope first, then the wp-config.php settings, then the database server, then a careful table repair, and a backup restore only when nothing else recovers the site. Follow the steps top to bottom and you will resolve most cases without guessing.

Check the Scope Before You Change Anything

Before you edit a single file, find out how widespread the problem is. Open the public site in a browser, then try to reach /wp-admin. The scope tells you where to look:

  • Both the site and wp-admin show the same error message: the connection itself is broken. This points to wp-config.php credentials or a database server that is down.
  • The front end loads but wp-admin reports a different problem: WordPress can reach the database, so this is usually corrupt tables rather than a credentials issue. WordPress may even offer a repair link.
  • Other sites on the same hosting account are also down: the database server or the host is the common cause, not your individual WordPress installation.

This is a different failure from a PHP fatal. If you also see a “critical error” notice, work through our guide on how to fix the WordPress critical error instead, because that path uses recovery mode and the debug log rather than database settings. For a broader map of WordPress failures and how they connect, keep our WordPress troubleshooting guide open alongside this one.

What Causes the Error Establishing a Database Connection

Almost every case traces back to one of these causes. Knowing the common cause up front keeps the fix focused:

  • Incorrect database credentials: the database name, username, password, or host in wp-config.php no longer matches what the database server expects. This is the single most frequent trigger, especially after a migration or a host-side password reset.
  • The database server is down or unresponsive: MySQL crashed, ran out of memory, or hit its connection limit because a traffic spike or a heavy plugin opened too many connections at once.
  • Corrupt database tables: an interrupted update, a hard server restart, or disk trouble left one or more tables in a broken state.
  • A migration or restore that did not finish: the files and database moved, but the new host, database name, or credentials in the config file were never updated.
  • A host or server-level issue: shared resources, a misconfiguration, or maintenance on the provider side.

A hacked site can also tamper with database access or inject a heavy load, so if you find unexpected admin users or strange files after recovery, follow up with our incident response steps for a hacked WordPress site.

The Fix Order: A Simple Decision Tree

Work the causes from cheapest to riskiest so you never restore a backup when a one-line credential edit would have done it:

  1. Confirm the scope (site versus wp-admin versus other sites on the host).
  2. Verify the database credentials in the wp-config.php file.
  3. Confirm the database server is running and reachable from the host.
  4. Repair corrupt tables with WordPress or phpMyAdmin.
  5. Test the connection and check the database user permissions.
  6. Restore from a clean backup only if the database itself is unrecoverable.

The first three steps resolve the large majority of cases. The later steps exist for the rare situations where the data, not the configuration, is the problem.

Step 1: Verify Database Credentials in wp-config.php

The wp-config.php file sits in the root directory of your WordPress installation. Open it with your hosting file manager, an FTP client, or the cPanel file editor and find these four lines:

  • DB_NAME is the database name.
  • DB_USER is the database username.
  • DB_PASSWORD is the password for that user.
  • DB_HOST is the hostname of the database server (often localhost, but many managed hosts use a dedicated address).

Compare each value against what your host shows for the database. In cPanel, open “MySQL Databases” to confirm the correct database name and the username attached to it. If you are unsure of the password, create a fresh one in that panel and paste the exact value into the wp-config.php file. A single wrong character in the password or an incorrect host is enough to break the database connection. Save the file, reload the site, and check whether the error message clears.

If you recently changed your host or moved servers, the DB_HOST value is the usual culprit. Replace localhost with the database server address your provider documents, then test again.

Step 2: Confirm the Database Server Is Running

If the credentials are correct and the error persists, check whether the database server itself is up. The quickest signal: if other WordPress sites on the same hosting account also throw the connection error, MySQL is down or overloaded rather than misconfigured for one site.

On managed or shared hosting you usually cannot restart the database service yourself, so this is the point to open a ticket and ask the support team to confirm the server is running and to restart MySQL if needed. On a VPS or server you control, restart the database service and review the MySQL error log for “too many connections” or out-of-memory entries.

A server that buckles under load is also a performance signal. If connection limits are hit during normal traffic, caching and a leaner query path will keep the database from being overwhelmed; our guide to reducing TTFB on WordPress covers the caching and server tuning that prevent these spikes from taking the database offline.

Step 3: Repair Corrupt Database Tables

When the front end works but wp-admin reports the database error, or when WordPress suggests a repair, your tables are likely corrupt. WordPress has a built-in repair tool that you enable with one line in wp-config.php:

define( 'WP_ALLOW_REPAIR', true );

Add that line, then visit https://yoursite.com/wp-admin/maint/repair.php in a browser. Choose “Repair Database” (or repair and optimize), let it finish, and then remove the line from the config file so the page is not left publicly accessible. Leaving repair enabled is a security risk because the page does not require a login.

If you prefer to use phpMyAdmin, open it from cPanel or your host dashboard, select the WordPress database, tick the affected tables, and choose “Repair table” from the actions menu. phpMyAdmin is also the easiest way to confirm the tables exist and that the database is not empty after a failed migration.

Step 4: Test the Connection and Check User Permissions

To prove whether the credentials and the database server agree, drop a small test script into the root directory next to wp-config.php. It uses the same mysqli extension WordPress relies on:

<?php
$link = mysqli_connect('DB_HOST', 'DB_USER', 'DB_PASSWORD', 'DB_NAME');
if (!$link) { die('Connection failed: ' . mysqli_connect_error()); }
echo 'Database connection successful';
mysqli_close($link);

Replace the placeholders with your real values, load the file in a browser, then delete it. A success message means the credentials and host are correct and the issue is elsewhere (usually corrupt tables). A failure message confirms a credentials or permissions problem. If the user exists but cannot connect, re-grant privileges or attach the database user to the database again in cPanel. The PHP manual documents the mysqli connection functions if you want the full reference.

Restore From a Backup When It Is the Safest Option

A restore is the last resort, used only when the database is genuinely unrecoverable: tables that will not repair, a dropped database, or visible data damage. Restoring overwrites current data, so reach for it only after the configuration and repair paths are exhausted.

Use a recent backup of your website that includes both the files and database, import the database through phpMyAdmin or your host backup tools, and confirm the wp-config.php credentials still match the restored database. This is exactly why a tested backup routine matters: with a clean copy, recovery from even a corrupt database is a short job rather than a rebuild.

Can Plugins or Themes Cause This Error?

Directly, rarely. A plugin or theme will not usually rewrite your database credentials. Indirectly, a poorly written plugin can flood the database server with queries until it hits its connection limit and refuses new connections, which surfaces as the same error message under load. If the error appears only at peak traffic and clears when traffic drops, treat it as a resource problem rather than a configuration one, and identify the heavy plugin through your host metrics or a query monitor.

Fixing the Error After a Migration

Moving a WordPress site is the classic way to trigger this error. After a migration, the files and database are in place, but the new environment often uses a different database name, username, password, or host. Open wp-config.php on the new server and reset all four values to match the destination database. If the site was installed at a new path, also confirm the table prefix in wp-config.php ($table_prefix) matches the imported tables. Getting these in sync is the single fix for most post-migration connection failures.

Prevent the Database Connection Error From Returning

A few habits keep this error from coming back:

  • Keep automated, off-server backups of both files and the database so a restore is always available.
  • Document your database credentials and update wp-config.php immediately whenever a host or password changes.
  • Add caching and right-size your hosting plan so traffic spikes never exhaust the database connection limit.
  • Monitor uptime and database load so you hear about a struggling MySQL server before visitors do.
  • Review plugins for query-heavy behavior during routine maintenance.

These are the same operational basics that keep the rest of a WordPress site stable, and they pay off across every emergency, not just this one.

When to Contact Your Hosting Provider

Contact your hosting provider when the credentials are confirmed correct, the database server appears down, other sites on the account are affected, or you cannot restart MySQL yourself on managed hosting. The host can verify the database service, check for server-side limits, and restore from their own backups if needed. WordPress.org documents the common WordPress errors and the broader debugging process if you want to dig deeper before opening a ticket.

If the site is business-critical and the error is costing you orders or leads, you do not have to work it alone. Our team handles emergency database and server recovery through GEENXT WordPress support, and we can get a site back online while protecting your data.

FAQ

What does “error establishing a database connection” mean in WordPress?

It means WordPress loaded its files but could not connect to the MySQL or MariaDB database that stores your content. The site looks offline, yet the data is almost always intact. The connection, not the content, is what failed.

What causes the error establishing a database connection in WordPress?

The most common causes are incorrect database credentials in wp-config.php, a database server that is down or overloaded, and corrupt database tables. A failed migration or a host-side issue can trigger it too.

How do I check and fix database credentials in WordPress?

Open wp-config.php in the root directory and compare DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST against the values in your host control panel. Correct any mismatch, save the file, and reload the site to see if the error clears.

How can I repair a corrupted WordPress database?

Add define( 'WP_ALLOW_REPAIR', true ); to wp-config.php, visit /wp-admin/maint/repair.php, run the repair, then remove the line. You can also repair the affected tables directly from phpMyAdmin.

How do I check if my database server is down?

If other sites on the same hosting account also show the error, the database server is likely down or overloaded. On managed hosting, ask your host to confirm and restart MySQL. On your own server, restart the service and read the MySQL error log.

Can plugins or themes cause a database connection error?

Rarely in a direct way. A heavy plugin can overload the database server with queries until it refuses new connections, which produces the same error under load. If the error appears only at peak traffic, treat it as a resource problem and find the query-heavy plugin.

How can I prevent this error in the future?

Keep tested off-server backups, update wp-config.php whenever credentials change, add caching, and right-size your hosting so traffic spikes never exhaust the connection limit. Monitoring database load gives you a warning before the site goes down.

When should I contact my hosting provider for this error?

Contact your host when the credentials are confirmed correct, the database server appears down, multiple sites on the account are affected, or you cannot restart MySQL yourself on managed hosting. The provider can verify the service and restore from server-side backups.

Avatar of Mark Anthony Garcia
Written by

Mark Anthony Garcia

Contributing author at GEENXT. Passionate about sharing knowledge and insights.

Next step

Need direct help after reviewing the guide?

Use the matching service lane or contact GEENXT for a more direct review of the issue, workflow, or decision path.

Contact GEENXT Browse the blog
Link copied to clipboard!