Severity: Critical · Fix time: 15–60 min · Skill level: Advanced

Error establishing a database connection is one of the most disruptive messages a WordPress site can display. It appears as a blank white screen with the text “Error establishing a database connection,” meaning WordPress cannot reach the MySQL or MariaDB database that stores all of your site’s content, settings, user accounts, and plugin data. When this error fires, both the public-facing website and the WordPress admin dashboard become completely inaccessible.

This error can happen to any WordPress site regardless of how well it’s maintained. A brief database server outage at the hosting provider, a misconfiguration in wp-config.php after a migration, a corrupted database table, or a traffic spike exceeding the hosting plan’s database connection limit — any of these can trigger it. The good news is that the causes fall into a short, predictable list, and diagnosing which one you’re dealing with narrows the fix path significantly.

Need a quick map of every WordPress error? See our 70+ WordPress Errors Guide → for a categorized reference of every common WordPress issue.

[Image: Browser screenshot showing the “Error establishing a database connection” white screen message]

How This Error Works

WordPress stores nearly everything in a relational database — posts, pages, settings, user accounts, plugin configuration, widget data, options. When WordPress loads any page, it queries that database dozens of times. The connection is established using credentials stored in wp-config.php: a database name, username, password, and hostname. If any part of that connection chain breaks — wrong credentials, an unavailable database server, a corrupted table, or an exhausted connection limit — the error appears.

The four root cause categories, in order of frequency:

1. Incorrect database credentials in wp-config.php The most common cause after a site migration or hosting change. If the DB_NAME, DB_USER, DB_PASSWORD, or DB_HOST values in wp-config.php don’t match what the new hosting environment expects, the connection fails immediately. This is a five-minute fix once identified.

2. Database server unavailable If your hosting provider’s MySQL server goes down, restarts, or runs out of memory, WordPress cannot connect even with perfectly correct credentials. This is a hosting infrastructure issue, not a WordPress issue, and typically resolves on its own or requires a support ticket to your host.

3. Corrupted database tables Database tables can become corrupted due to sudden server shutdowns, failed plugin updates, or disk errors. WordPress has a built-in repair tool accessible at /wp-admin/maint/repair.php (after temporarily enabling it in wp-config.php) that can fix some forms of corruption. Severe corruption may require restoring from a backup.

4. Database connection limit exceeded Shared hosting plans limit simultaneous database connections. A traffic spike, a misbehaving plugin making excessive queries, or a DDoS attack can push a site over that limit, triggering the error for new connection attempts while existing connections are still open.

Check This First — 2-Minute Diagnostic

  1. Check your hosting provider’s status page — If their MySQL server is down, you’ll see an incident notice. This rules out all WordPress-side fixes being useful until the host resolves the infrastructure issue.
  2. Access /wp-admin directly — Navigate to yourdomain.com/wp-admin. If you see “One or more database tables are unavailable,” WordPress is partially connecting — the issue is likely corruption rather than credentials. If both frontend and admin show the same connection error, incorrect credentials or a server outage are more likely.
  3. Verify wp-config.php credentials — Connect via SFTP and open wp-config.php. Confirm that DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST match what your hosting control panel shows for your database.
  4. Test the database connection manually — Log into phpMyAdmin via your hosting control panel using the same credentials listed in wp-config.php. If phpMyAdmin connects successfully, the credentials are correct and the issue is elsewhere.
  5. Check for a plugin or recent update — Review your error log in cPanel for the timing of the error. A plugin update that ran right before the error appeared often points to a database table modification that went wrong.

Purpose & Benefits

1. Restoring Site Availability and Protecting Revenue

Every minute your site displays this error is a minute visitors see a broken page. For eCommerce sites, service businesses, and lead-generation sites, downtime has a direct cost — lost orders, missed inquiries, damaged trust. Knowing the common causes and how to diagnose them efficiently gets your site back online with minimal impact. In our experience managing WordPress sites, the credential check alone resolves the majority of post-migration database connection errors within minutes.

2. Preventing Data Loss During Active Corruption

When the error is caused by database corruption, acting quickly matters. Allowing a partially corrupted database to continue receiving writes can expand the scope of corruption. The right response: take the site offline temporarily, run the WordPress repair tool or restore from a clean backup, and verify data integrity before bringing it back online. A database corrupted further by continued write attempts is harder to recover than one where writes were stopped promptly.

3. Identifying Underlying Infrastructure Problems

A recurring database connection error often signals a hosting infrastructure issue — insufficient server resources, an overloaded shared environment, or a plan that’s no longer right for the site’s current traffic level. Resolving the immediate error without addressing the root cause leads to recurrence. The pattern of when errors occur — time of day, traffic volume, correlation with specific plugin operations — provides the data needed to make the right infrastructure decision.

Examples

1. Migrated Site with Stale wp-config.php Credentials

A business migrates their WordPress site from one hosting provider to another. The new host creates a new database with a different name and credentials than the original. The migration company copies all files correctly, but wp-config.php still references the old database credentials. The site immediately displays the database connection error on the new host. The fix takes approximately five minutes:

// Open wp-config.php via SFTP and update these four values
// Match them exactly to what your new host's control panel shows

define( 'DB_NAME', 'new_database_name' );
define( 'DB_USER', 'new_database_user' );
define( 'DB_PASSWORD', 'new_database_password' );
define( 'DB_HOST', 'localhost' ); // Usually 'localhost' but may be a specific host string

After saving wp-config.php, reload the site. If credentials are now correct, the site loads immediately.

2. Plugin Update Corrupts a Database Table

A WordPress site running WooCommerce performs a plugin update that fails mid-execution due to a brief server interruption. The update partially modifies a database table, leaving it in a corrupted state. The next page load triggers the connection error. The fix: temporarily add define('WP_ALLOW_REPAIR', true); to wp-config.php, navigate to yourdomain.com/wp-admin/maint/repair.php, run the repair tool, then remove the WP_ALLOW_REPAIR line immediately afterward:

// Temporarily add to wp-config.php to enable the repair tool
// REMOVE THIS LINE after running the repair — it's a security risk to leave in place
define( 'WP_ALLOW_REPAIR', true );

After the repair completes, check whether the plugin update needs to be re-run or rolled back.

3. Shared Hosting Connection Limit Exceeded During a Traffic Event

A small business runs a promotion that drives significantly more concurrent traffic than usual. Their shared hosting plan has a maximum of 15 simultaneous database connections. During peak traffic, the site exceeds this limit and intermittently shows the database error to new visitors. The immediate fix: enable object caching to reduce the number of database queries per page load, significantly reducing the number of concurrent connections required. The longer-term fix: upgrade to a hosting plan with higher connection limits or move to a managed WordPress host where database connection pooling is handled at the infrastructure level.

Common Mistakes to Avoid

  • Editing wp-config.php without downloading a backup first — Before modifying any configuration file, download a copy to your local machine first. A typo in wp-config.php can take your site from one error to a completely non-functional state. Work in a text editor, not in a browser-based file manager where accidental characters are hard to spot.
  • Assuming the problem is always in WordPress — Many database connection errors originate at the server or hosting level, not in WordPress or its configuration. Before spending hours troubleshooting wp-config.php, check your hosting provider’s status page and your error logs for server-side indicators.
  • Not addressing the root cause after restoring from backup — Restoring from a backup is the right emergency move if you have one. But if the error returns after restoration, the restoration was a temporary fix, not a solution. Investigate why the error occurred — wrong credentials, server capacity, plugin conflicts — before considering the issue closed.
  • Operating without regular automated backups — If database corruption requires a restore and you have no recent backup, you may lose substantial site data. This error is a stark reminder that reliable, automated, offsite backups are not optional for any site that matters to your business.
  • Leaving WP_ALLOW_REPAIR in wp-config.php — The database repair tool is useful but should never be left enabled on a production site. Anyone who discovers the repair URL can trigger database operations. Remove define('WP_ALLOW_REPAIR', true); from wp-config.php immediately after running a repair.

Best Practices

1. Maintain Regular, Automated Offsite Backups

A reliable backup strategy is your safety net for database connection errors caused by corruption or failed updates. Use a backup plugin that stores copies offsite — not just on the same server as your site — and runs automated daily backups. Having a clean database backup from 24 hours ago changes a potential data loss crisis into a routine restore. For sites where data changes frequently (active eCommerce, frequently updated content), more frequent backups — every 6 or 12 hours — are worth the small additional cost.

2. Use Managed WordPress Hosting for Business-Critical Sites

Managed WordPress hosting providers monitor server health, handle database optimization, and provide faster support response when issues arise. For sites where downtime directly impacts revenue — eCommerce stores, booking systems, lead-generation sites — the additional cost of managed hosting is worth it. Managed hosts also handle database server maintenance and capacity planning, eliminating the most common infrastructure-level causes of this error. Our WordPress hosting services are configured specifically for WordPress database workloads.

3. Implement Object Caching to Reduce Database Load

Object caching stores frequently accessed database query results in memory, dramatically reducing the number of times WordPress needs to connect to the database on each page load. This both improves site performance and reduces the risk of hitting database connection limits during traffic spikes. Redis and Memcached are the most commonly used object caching backends for WordPress.

// Enable object caching in wp-config.php
// Requires Redis or Memcached server and a compatible caching plugin
define( 'WP_CACHE', true );

// For Redis object caching (with Redis Object Cache plugin):
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );

4. Monitor Database Table Health Periodically

Use phpMyAdmin or a database maintenance plugin to check database table health on a regular schedule. Tables accumulate overhead, fragmentation, and orphaned data over time — not all of which causes immediate problems, but which increases the risk of corruption during server interruptions. Running OPTIMIZE TABLE and CHECK TABLE operations periodically keeps database tables in clean condition.

5. Set Up Uptime Monitoring with Immediate Alerts

You shouldn’t find out about a database connection error from a customer. Uptime monitoring services check your site every 1-5 minutes and send an immediate alert when error responses are detected. Early detection compresses recovery time: you can have a support ticket with your host open within minutes of the error starting, rather than discovering it has been displaying for hours.

Frequently Asked Questions

What causes the “Error establishing a database connection” error most often?

The most common cause — especially after a site migration or hosting change — is incorrect database credentials in wp-config.php. The DB_NAME, DB_USER, DB_PASSWORD, or DB_HOST values don’t match what the hosting environment actually requires. After credentials, the next most frequent causes are a hosting provider’s database server being temporarily unavailable, and database table corruption from a failed update or server interruption.

How do I fix this error when locked out of wp-admin?

Connect to your site via SFTP and open wp-config.php. Verify all four database credential constants (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST) match what your hosting control panel shows for your database. Test those same credentials in phpMyAdmin — if phpMyAdmin connects, the credentials are correct and the issue is likely a corrupted database or server-side outage. If phpMyAdmin also fails, contact your hosting provider — the database server itself may be down.

Can this error hurt my SEO?

Brief downtime has minimal SEO impact. Google’s crawlers don’t immediately penalize brief unavailability. Extended downtime — 24 hours or more — can begin to affect crawl behavior and, in extreme cases, rankings. Resolve the error quickly, and SEO impact is generally negligible. Once the site is back online, submit your XML sitemap through Google Search Console to prompt faster reindexing.

Will this error delete my data?

No. The error means WordPress cannot access the database — not that the database is gone. In most cases, your data is intact and temporarily inaccessible. Once the connection issue is resolved, everything returns to normal. The exception is active corruption that progresses while the error is unresolved, which is why acting quickly and stopping writes to a corrupted database matters.

How long does it typically take to fix?

A credential issue in wp-config.php takes 5-15 minutes once you identify the mismatch. A server-side hosting outage typically resolves within an hour as the host addresses it. Database corruption requiring the repair tool takes 15-30 minutes. A restoration from backup takes 30 minutes to a few hours depending on site size and your backup system’s tooling. Having a recent backup dramatically compresses recovery time regardless of cause.

Related Glossary Terms

How CyberOptik Can Help

Still broken? Our team fixes WordPress errors like this in under 30 minutes for maintenance clients. A database connection error on a live site is an emergency — and diagnosing the cause quickly requires knowing exactly where to look and having direct server access to look there. We manage WordPress infrastructure and maintenance for clients, including database credential verification, corruption repair, and hosting configuration, so when something goes wrong, we know the fastest path to resolution. Contact us immediately if your site is down or learn about our WordPress maintenance services.