Skip to main content

WordPress Troubleshooting

Fixing 'Error Establishing a Database Connection' in WordPress

This error means WordPress can't reach its database at all — here's how to check credentials, confirm the database exists, repair corruption, and rule out the server itself.

4

Credentials in wp-config.php to verify first

wp_options

Table most often corrupted in this error

Daily

Backups as a restore point if repair fails

24/7

Human support for server-side database issues

In short

'Error establishing a database connection' means WordPress cannot connect to its MySQL database at all, which is different from a slower or partially broken site — nothing loads, including wp-admin. The most common causes, in order of likelihood, are incorrect database credentials or hostname in wp-config.php, a database that was deleted or renamed, a corrupted database table (often wp_options), or the database server itself being down or overloaded on the hosting side.

Fixing it means checking each cause in sequence: verify the four database settings in wp-config.php match what actually exists, confirm the database itself is present, attempt a repair if it exists but is corrupted, and contact hosting support if the database server itself appears to be the problem.

This error sits one level below most WordPress problems — it's not a plugin conflict or a theme bug, it's WordPress being unable to reach the database that holds every post, page, setting and user account. Because nothing in WordPress works without that connection, the error appears identically on the front end and in wp-admin, and no amount of plugin troubleshooting will fix it if the actual cause is a wrong password or a missing database.

The upside is that the causes are a short, well-defined list, and each one has a specific, checkable fix rather than requiring guesswork. Working through them in order — credentials, database existence, corruption, then server-side issues — resolves the overwhelming majority of cases without needing a full restore.

Step 1: Check the Database Credentials in wp-config.php

Open wp-config.php via FTP or File Manager and check the four database definitions near the top: DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. Compare each against what actually exists in your hosting panel's database section — a typo in any one of these, or a database user whose password was reset and never updated in this file, produces exactly this error with no other symptom.

DB_HOST is worth checking specifically even though it's the one people assume is always 'localhost' — some hosting environments use a different hostname or a non-standard port for the database server, and using the wrong one connects to nothing even with a perfectly correct username and password. Confirm the exact hostname your hosting panel specifies, rather than assuming localhost is universal.

Step 2: Confirm the Database Actually Exists

Log in to your hosting panel's database management tool (phpMyAdmin or similar) and confirm the database named in DB_NAME is actually listed and contains WordPress's tables (wp_posts, wp_options, wp_users, and so on). A database that was accidentally deleted, renamed during a migration, or never fully created in the first place produces this exact error, and no amount of credential-checking in wp-config.php fixes it if the database itself isn't there.

If the database is missing entirely and you have a recent backup, restoring it recreates both the database and its data in one step. If no backup exists, a completely empty install at least gets the site responding again, though content recovery at that point depends entirely on what backup options remain.

Step 3: Repair a Corrupted Database Table

If the database exists and credentials check out, corruption in a specific table is the next likely cause — wp_options is the most common culprit, since it's WordPress's central settings table and gets written to constantly. Add define('WP_ALLOW_REPAIR', true); to wp-config.php, then visit yoursite.com/wp-admin/maintenance.php in a browser, which reveals a Repair Database (or Repair and Optimize Database) button.

Run the repair, then remove the WP_ALLOW_REPAIR line from wp-config.php afterward — leaving this maintenance page publicly accessible is a real security exposure since anyone who finds the URL can run repair operations on your database. If repair completes but the error persists, the corruption may be more extensive than a standard repair addresses, which points back toward restoring from a recent backup instead.

Step 4: Rule Out a Server-Side Database Problem

If credentials are correct, the database exists, and repair either isn't needed or didn't help, the issue may be on the hosting side entirely — a database server that's temporarily down, overloaded by too many simultaneous connections, or hitting a resource limit tied to your hosting plan. This is where the fix moves out of your hands and into your host's, since you can't repair infrastructure you don't have direct access to.

24/7 human support exists specifically for this stage of troubleshooting: a support team can check the actual database server's status, connection limits and error logs directly, which isn't visible from wp-config.php or phpMyAdmin alone. If the same database connection error recurs repeatedly under normal traffic, that's also a sign the hosting resources themselves, not a one-time glitch, need addressing.

Fix 'Error Establishing a Database Connection'

When the Database Itself Is the Problem

A database connection error sits below the WordPress layer entirely, which is exactly why it needs a hosting environment where the database server itself is stable and properly resourced.

Hosting Cheap runs on pure NVMe SSD storage with 24/7 human support able to check database server status directly when a connection error points to something on the hosting side.

  • phpMyAdmin access to confirm database existence and repair tables
  • NVMe SSD storage for fast database repair and restore operations
  • Daily backups as a full restore point if repair doesn't resolve it
  • 24/7 human support to check server-side database status directly

Why Hosting Cheap

What you get

phpMyAdmin database access

Confirm a database exists, inspect its tables, and run repair operations directly.

NVMe SSD storage

Database repair and restore operations complete quickly rather than adding to downtime.

Daily backups

A recent full restore point exists if a database is missing, deleted, or too corrupted to repair.

Free managed migration

Move a site with recurring database issues to hosting with more stable, better-resourced infrastructure.

24/7 human support

Get a direct check on the database server's status when the cause isn't visible from wp-config.php alone.

30-day money-back guarantee

Test hosting stability risk-free if database connection errors were a recurring problem elsewhere.

How It Works

Get set up in a few steps

1

Verify wp-config.php database credentials

Check DB_NAME, DB_USER, DB_PASSWORD and DB_HOST against what your hosting panel actually shows.

2

Confirm the database exists and repair if corrupted

Check phpMyAdmin for the database and its tables, then use WP_ALLOW_REPAIR if wp_options or another table is corrupted.

3

Contact support if the server itself is the cause

Get a direct check on database server status, connection limits and logs if credentials and repair don't resolve it.

Included

Everything you need, on every plan

  • DB_NAME, DB_USER, DB_PASSWORD and DB_HOST checked against the hosting panel
  • Database hostname confirmed rather than assumed to be localhost
  • Database existence confirmed in phpMyAdmin, with WordPress tables present
  • WP_ALLOW_REPAIR used to run a database repair if a table looks corrupted
  • WP_ALLOW_REPAIR line removed from wp-config.php after repair completes
  • Recent backup identified as a restore point if repair doesn't resolve it
  • Support contacted to check server-side database status if the cause remains unclear

FAQ

Frequently asked questions

Why does WordPress say 'error establishing a database connection'?

It means WordPress can't reach its MySQL database at all, most commonly due to wrong credentials or hostname in wp-config.php, a missing or renamed database, table corruption, or a server-side database problem. The fix depends on which of these is the actual cause.

How do I check my WordPress database credentials?

Open wp-config.php via FTP or File Manager and compare DB_NAME, DB_USER, DB_PASSWORD and DB_HOST against what your hosting panel's database section actually shows. A mismatch in any one of these produces this exact error.

What is the wp_options table and why does it get corrupted?

wp_options stores WordPress's core settings and is written to constantly by plugins, themes and WordPress core itself, which makes it more exposed to corruption from an interrupted write or a server crash mid-update. It's the most common single table involved in this error.

How do I repair a corrupted WordPress database?

Add define('WP_ALLOW_REPAIR', true); to wp-config.php, then visit yoursite.com/wp-admin/maintenance.php to access a Repair Database button. Remove that line from wp-config.php again once repair is finished, since the maintenance page is otherwise publicly reachable.

Is this error something I can fix myself, or does it need hosting support?

Credential mismatches, missing databases, and table corruption are all things you can check and fix directly through wp-config.php and phpMyAdmin. If those all check out and the error persists, it's usually a server-side database issue that needs your host's support team to investigate.

Will restoring a backup fix a database connection error?

Yes, if the database was deleted, badly corrupted beyond what a repair fixes, or the credentials tied to it are unrecoverable, restoring a recent backup recreates a working database and its content in one step. This is why daily backups matter even for an error that looks purely technical.

Ready for Hosting With Stable Database Infrastructure?

Get managed WordPress hosting with daily backups and 24/7 support, from $4.19/mo.

Get Started