localwebadvisor
WIKI← Wiki home

What Is 'Error Establishing a Database Connection'?

By FayUpdated Jul 10, 2026EVERGREEN
⚡ THE ANSWER

'Error establishing a database connection' is a WordPress message shown when the site's code cannot connect to its MySQL or MariaDB database, so no content can load and the whole site goes down. WordPress stores every post, page, setting, and user in that database, so if the connection fails, there is nothing to display. Common causes include wrong database credentials in wp-config.php, a crashed or overloaded database server, a corrupted database, or exceeding your host's resource limits. Fixing it means restoring the connection between the site's files and its database.

What it affects
The entire WordPress site goes offline, not just one page
Root cause
WordPress cannot connect to its MySQL/MariaDB database (WordPress.org)
Top triggers
Wrong credentials in wp-config.php, crashed database, resource limits
Key file
Database name, user, password, and host live in wp-config.php
Common on
Overloaded shared hosting during traffic spikes (typical hosting cause)

What this error actually means #

The message error establishing a database connection appears when WordPress cannot reach the database that stores all of its content. WordPress keeps every post, page, comment, setting, plugin option, and user account in a MySQL or MariaDB database, and its PHP code queries that database on every page load. When the connection fails, WordPress has no data to build the page, so instead of your site, visitors see this stark error, and the whole site, front end and admin dashboard alike, goes dark. Because it takes down everything at once, it is one of the more alarming WordPress failures, but it is also usually fixable once you identify why the connection dropped. The problem lies in the link between the site's files and its database, not in the design or content itself. If your site is showing this error and you cannot recover it, our /services/website-rescue team specializes in bringing downed WordPress sites back quickly.

How WordPress connects to its database #

To troubleshoot this error, it helps to know how the connection is made. WordPress stores its database credentials in a file called wp-config.php in the site's root directory. Four values matter: the database name, the database username, the password, and the database host, usually localhost on shared hosting but sometimes a separate server address. On every request, WordPress reads these values and opens a connection to the database server to run its queries. If any credential is wrong, if the database server is down, or if the host address is incorrect, the connection cannot be established and the error appears. This is why a change that seems unrelated, such as a host migration that alters the database host, or a security reset that changes the password, can suddenly break a previously working site. Understanding this handshake points you straight to the likely culprits. Our /services/wordpress-development team works with these configuration files daily and knows the common failure points.

The most common causes #

This error has a well-known shortlist of causes. The first and most frequent is incorrect database credentials in wp-config.php, often after a migration, a host change, or a password reset left the file out of sync with the database. The second is a database server that has crashed or is unresponsive, which can happen on shared hosting when the server is overloaded. The third is exceeding your hosting resource limits: a traffic spike or an inefficient plugin can exhaust available database connections or memory, and the host temporarily refuses new connections. The fourth is a corrupted database, where a table becomes damaged and queries fail. Less commonly, a hacked site, a failed update, or a full disk can produce the same message. Because the causes range from a one-character typo to a host-wide outage, diagnosis works best as a checklist. Our /services/managed-hosting page covers the server-side capacity and stability issues that trigger many of these connection failures.

Checking credentials in wp-config.php #

The first practical step is confirming the database credentials, since a mismatch here is the leading cause. Open wp-config.php and verify each value matches what your host provides in its control panel or hosting dashboard. A single wrong character breaks the connection.

Example
<?php
// wp-config.php - these four values must exactly match your host's database

define( 'DB_NAME',     'wp_myshop_db' );      // database name
define( 'DB_USER',     'wp_myshop_user' );    // database username
define( 'DB_PASSWORD', 'S3cure-P@ssw0rd!' );  // database password
define( 'DB_HOST',     'localhost' );         // often localhost;
                                              // some hosts use an IP
                                              // or a name like
                                              // mysql.hostname.com

// If unsure, copy the exact values from your hosting control panel
// (cPanel > MySQL Databases, or your host's database section).
?>

When the database server is down or overloaded #

If your credentials are correct but the error persists, the database server itself may be down or overwhelmed. On shared hosting, your database runs alongside many others, and a spike in traffic, either yours or a neighbour's, can exhaust the server's connection pool or memory, causing it to refuse new connections until load drops. An inefficient plugin, an uncached site, or a sudden burst of visitors can all push you past your host's limits. Symptoms include the error appearing intermittently, especially under load, and clearing on its own when traffic subsides. The short-term fix is to wait or restart the database service if you have access; the real fix is reducing load through caching, optimizing heavy queries, and, if you routinely outgrow your plan, moving to more capable hosting. Persistent overload is a strong signal you need better resources. Our /services/speed-optimization and /services/managed-hosting teams reduce database load and provide capacity that handles your real traffic without collapsing.

Repairing a corrupted database #

Sometimes the connection is available but a database table has become corrupted, producing the same error or a partial one. Corruption can result from an interrupted write, a crashed server, a failed update, or a full disk. WordPress includes a built-in repair tool you can enable by adding a single line to wp-config.php, which then lets you run a repair-and-optimize routine from a special URL. For safety you remove that line once the repair is done, since the tool is accessible without logging in while enabled. If the built-in tool cannot fix it, your host's database manager, such as phpMyAdmin, offers a repair option on individual tables, and your host may have a more robust recovery process. Crucially, before attempting any repair, take a backup of the database, because repair operations occasionally worsen damage. If you lack a recent backup, that itself is a problem worth solving. Our /services/care-plans include regular backups precisely so a corrupted database is a quick restore, not a disaster.

Ruling out hacks and failed updates #

When the usual causes do not explain the error, consider whether a security breach or a botched update is responsible. A compromised WordPress site can have its files or database altered in ways that break the connection or corrupt data, and this error sometimes accompanies an attack. Similarly, a plugin or core update that failed midway, or a disk that filled up during the process, can leave the database in a broken state. Look for other warning signs: unexpected admin users, modified core files, spam content, or a recent update that coincided with the error. If you suspect a hack, restoring from a clean backup taken before the compromise is usually the safest path, followed by hardening the site to prevent reinfection. Guessing your way through a hacked database can leave malicious code behind, so this is a case where professional help pays off. Our /services/website-security and /services/website-rescue teams clean compromised sites and restore a healthy, secure database connection.

Why backups and staging are your safety net #

The single biggest factor in how badly a database connection error hurts you is whether you have recent backups. With automated, off-site backups of both files and the database, a corrupted table or a bad configuration change becomes a quick restore rather than a frantic rebuild or lost content. Without them, a serious database failure can mean permanently losing posts, orders, or customer accounts. Just as important is a staging environment, a private copy of your site where updates and changes are tested before they touch the live site. Many database errors follow a plugin update, a core upgrade, or a migration, and testing those on staging first catches the failure before any customer sees it. Together, backups and staging turn database emergencies from disasters into minor inconveniences. They also let you experiment and recover confidently rather than fearing every update. This safety net is exactly what our /services/care-plans provide, combining scheduled backups, a staging workflow, and managed updates so a broken database connection is always recoverable in minutes.

Preventing this error and recovering fast #

The best protection against this error is preparation. Keep automated, off-site backups of both your files and database so any corruption or bad change is a quick restore rather than a rebuild. Use caching and keep plugins lean so your database is not needlessly hammered on every visit, which reduces overload-driven failures. Choose hosting sized for your real traffic, and monitor uptime so you learn about an outage immediately. Store your database credentials securely and update wp-config.php carefully during any migration or password change, since a mismatch here is the single most common trigger. When the error does strike, work the checklist: verify credentials, check whether the database server is up, look for overload, then test for corruption or compromise. Because the whole site is down while this error is live, speed of recovery matters for both revenue and reputation. Our /services/website-rescue, /services/managed-hosting, and /services/care-plans exist to get WordPress sites back online fast and keep them stable.

FAQ

What does 'error establishing a database connection' mean?

It means WordPress cannot connect to the database that stores all your content, so nothing can load and the entire site goes offline. Every post, page, and setting lives in that database, so without the connection there is nothing to show. It usually stems from wrong credentials, a down database server, or a corrupted database.

How do I fix the WordPress database connection error?

Start by checking the database name, username, password, and host in wp-config.php against what your hosting control panel shows, since a mismatch is the top cause. If those are correct, check whether the database server is down or overloaded, try the built-in database repair tool, and rule out a hack or failed update. Restore from backup if needed.

Why did my WordPress site suddenly show this error?

Common triggers are a recent migration or password change that left wp-config.php out of sync, a traffic spike overloading a shared database server, a corrupted table, a failed update, or a full disk. Occasionally a hacked site causes it. Something broke the link between your site's files and its database; identifying the recent change usually points to the cause.

Is this error a sign my site was hacked?

Not usually, but it can be. Most cases are wrong credentials or an overloaded or corrupted database. However, a compromised site can alter files or the database in ways that break the connection. If you also see unexpected admin users, modified files, or spam content, treat it as a possible breach and restore from a clean backup, then harden security.

Can too much traffic cause this database error?

Yes. On shared hosting, a traffic spike can exhaust the database server's available connections or memory, so it temporarily refuses new connections and WordPress shows this error. It often appears intermittently under load and clears when traffic drops. Caching, optimizing queries, and moving to hosting sized for your traffic prevent overload-driven failures.

How do I repair a corrupted WordPress database?

First back up the database. Then enable WordPress's built-in repair tool by adding a line to wp-config.php and visiting the repair URL, removing the line afterward for security. If that fails, use your host's database manager, such as phpMyAdmin, to repair the affected tables, or ask your host. A clean recent backup is the safest recovery when repair does not work.

How Local Web Advisor checks this for you

Is your own website getting web tech right?

Our free AI audit scans your site and tells you — in plain English — exactly what to fix for web tech and seven other areas, with the business impact and the fix for each. No login needed to start.

Run my free website audit →

Was this helpful?