Hsnime
Business

How to Fix “Error Establishing a Database Connection” in WordPress

How to Fix “Error Establishing a Database Connection” in WordPress

“Error establishing a database connection” means WordPress cannot reach your MySQL database — the fix is almost always in your wp-config.php credentials, a corrupted database, or an overloaded database server, and you can usually confirm which one in under five minutes.

Why This Error Happens

WordPress stores every post, page, and setting in a MySQL database. This error appears the moment WordPress can’t talk to that database, usually because of:

  • Incorrect database credentialsin wp-config.php
  • A corrupted database table, often wp_options or wp_posts
  • The database server being down or overloaded
  • An incorrect database hostvalue (rare, but common after migrations)

How to Fix It Step by Step

Step 1: Verify Your Database Credentials

Open ‘wp-config.php’ via FTP and confirm these four values match exactly what’s in your hosting control panel:

  • ‘DB_NAME’
  • ‘DB_USER’
  • ‘DB_PASSWORD’
  • ‘DB_HOST’

A single typo or an outdated password after a migration is the #1 cause of this error.

Step 2: Check If Your Database Server Is Down

Log into phpMyAdmin (via cPanel or your hosting dashboard). If it also fails to load, the database server itself may be down — this is a hosting-side issue, not something you can fix from WordPress files.

Step 3: Repair the Database

If phpMyAdmin loads but WordPress still shows the error, add this line temporarily to ‘wp-config.php’:

  • ‘define( ‘WP_ALLOW_REPAIR’, true );’

Then visit ‘yoursite.com/wp-admin/maint/repair.php’ and click Repair Database. Remove the line afterward for security.

Step 4: Confirm the Database User Has Correct Privileges

In phpMyAdmin or your host’s database manager, make sure the database user has ALL PRIVILEGES on that specific database — a missing privilege after a server migration is a common, overlooked cause.

Step 5: Contact Hosting Support for Server-Level Issues

If credentials are correct and the database itself won’t load in phpMyAdmin, this is almost certainly a resource or server outage your host needs to resolve.

Diagnosis Table

Test Result What It Means
Load phpMyAdmin Fails to load Database server is down — contact host
Load phpMyAdmin Loads fine Credentials or table corruption issue
Check wp-config.php Values don’t match host panel Update DB_NAME/DB_USER/DB_PASSWORD
Run repair.php Reports repaired tables Corrupted table was the cause
Check user privileges Missing ALL PRIVILEGES Re-grant privileges in database manager

 

Preventing This Error in the Future

  • Keep a saved copy of your correct DB credentials somewhere safe outside wp-config.php
  • Schedule regular database backups (daily, if your site publishes often)
  • Avoid running many heavy plugins on shared hosting — database overload is common on cheap plans

Helpful Resources & Authority Links

Related Articles