GuidesJan 17, 20267 min read

Why Does My Site Show 'Error Establishing Database Connection'?

Fix the dreaded 'Error establishing a database connection' WordPress error. Learn the causes and step-by-step solutions to get your site back online.

"Error establishing a database connection" is one of the most common and frustrating WordPress errors. Your site is completely down, and you need to fix it fast.

Here's what causes this error and how to fix it, step by step.

What This Error Means

WordPress stores all your content (posts, pages, settings, users) in a MySQL database. When WordPress can't connect to that database, you see this error.

The database connection requires:

  1. Correct database name
  2. Correct database username
  3. Correct database password
  4. Database server running
  5. Enough server resources

If any of these fail, you get the error.

Quick Diagnosis

Check if Database Server is Down

Test 1: Can you access phpMyAdmin?

  1. Log into hosting control panel (cPanel)
  2. Click phpMyAdmin
  3. If it loads, database server is running

Test 2: Check admin vs frontend

  • If yoursite.com/wp-admin/ shows different error mentioning "repair," database may be corrupted
  • If both show same error, likely credentials or server issue

Common Causes & Fixes

Cause 1: Wrong Database Credentials

Most common cause. The wp-config.php file has incorrect database settings.

How it happens:

  • Password was changed
  • Database was moved
  • Typo in credentials
  • Migration issues

Fix:

  1. Access your files via FTP/SFTP or File Manager

  2. Open wp-config.php in root directory

  3. Find these lines:

define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_username');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');
  1. Verify credentials in cPanel:

    • Go to MySQL Databases
    • Check database name matches DB_NAME
    • Check username matches DB_USER
    • Note: Password isn't shown, may need to reset
  2. Reset password if unsure:

    • In cPanel → MySQL Databases
    • Find the user → Change Password
    • Update wp-config.php with new password
  3. Save and test

Cause 2: Database Server is Down

Your hosting's MySQL server is temporarily offline.

Symptoms:

  • Error appeared suddenly
  • No changes were made
  • Multiple sites affected (if you have several)

Fix:

  1. Wait 5-10 minutes - Often resolves itself
  2. Check host's status page for outages
  3. Contact host support if persists
  4. Check resource limits - May be suspended for overuse

Cause 3: Corrupted Database

Database tables can become corrupted, especially after crashes or resource limits.

Symptoms:

  • wp-admin shows: "One or more database tables are unavailable. The database may need to be repaired."

Fix Option 1: WordPress Repair

  1. Add to wp-config.php (before "That's all, stop editing!"):
define('WP_ALLOW_REPAIR', true);
  1. Visit: yoursite.com/wp-admin/maint/repair.php

  2. Click "Repair Database" or "Repair and Optimize"

  3. Remove the line from wp-config.php when done (security risk if left)

Fix Option 2: phpMyAdmin Repair

  1. Open phpMyAdmin
  2. Select your WordPress database
  3. Select all tables (check boxes)
  4. Choose "Repair table" from dropdown
  5. Execute

Cause 4: Exceeded Database Connections

Too many simultaneous connections to database.

Symptoms:

  • Error comes and goes
  • Happens during traffic spikes
  • May see "Too many connections" in logs

Causes:

  • Traffic spike
  • Poorly coded plugin
  • Bot attack

Fixes:

  1. Wait for traffic to subside

  2. Increase max connections (if you have access):

max_connections = 500
  1. Optimize slow queries:

    • Install Query Monitor plugin
    • Identify slow database queries
    • Fix or remove problematic plugins
  2. Upgrade hosting if consistently hitting limits

Cause 5: Database Host Wrong

The DB_HOST value in wp-config.php is incorrect.

Common values:

  • localhost - Most shared hosting
  • 127.0.0.1 - Same as localhost
  • mysql.yourdomain.com - Some hosts
  • Specific IP or hostname - Cloud/VPS setups

Fix:

  1. Check your host's documentation
  2. Contact support for correct value
  3. Common hosts:
    • Most shared: localhost
    • GoDaddy: Often specific hostname
    • SiteGround: localhost
    • Bluehost: localhost

Cause 6: Insufficient Server Resources

Your hosting plan ran out of memory, CPU, or disk space.

Symptoms:

  • Multiple issues, not just database
  • Error in server logs about resources
  • Host sends warning emails

Fixes:

  1. Check disk space:

    • cPanel → Disk Usage
    • Clear old backups, logs, unused files
  2. Check resource usage:

    • cPanel → Resource Usage
    • Identify spikes or overuse
  3. Upgrade plan if consistently maxed out

  4. Optimize site:

    • Remove unused plugins
    • Optimize images
    • Add caching

Cause 7: Plugin or Theme Conflict

A recent plugin/theme update corrupted database or causes excessive queries.

Symptoms:

  • Error started after update
  • Error after activating plugin

Fix:

  1. Access files via FTP

  2. Rename plugins folder:

/wp-content/plugins/ → /wp-content/plugins_disabled/
  1. Check if site loads

  2. If yes, rename back to plugins/

  3. Rename plugins one by one to find culprit:

/wp-content/plugins/problem-plugin/ → /wp-content/plugins/problem-plugin_disabled/
  1. Delete or replace problematic plugin

Advanced Troubleshooting

Check MySQL Error Logs

In cPanel:

  1. Go to Errors in cPanel
  2. Check for MySQL-related errors

Via SSH:

tail -100 /var/log/mysql/error.log

Test Database Connection Manually

Create a test file test-db.php in your root:

<?php
$link = mysqli_connect('localhost', 'your_user', 'your_password', 'your_database');

if (!$link) {
    die('Connection failed: ' . mysqli_connect_error());
}

echo 'Connected successfully';
mysqli_close($link);
?>

Visit yoursite.com/test-db.php - delete after testing!

Check if Database Exists

  1. Log into phpMyAdmin
  2. Look for your database name in left sidebar
  3. If missing, database may have been deleted
  4. Restore from backup

Prevention

Regular Backups

Use backup plugins or host backups:

  • UpdraftPlus (free)
  • Host's backup feature
  • BlogVault (premium)

Monitor Database Health

  • Use WP-Optimize plugin for maintenance
  • Schedule regular database optimization
  • Keep plugins updated

Use Quality Hosting

Reliable hosts have:

  • Better MySQL configurations
  • More stable servers
  • Proactive monitoring

Consider: SiteGround, Kinsta, Cloudways

FAQ

Why did this happen suddenly?

Common sudden causes:

  • Host server issue
  • Resource limit hit
  • Automatic password rotation (rare)
  • Database corruption from crash

Can I lose my content?

If the database is deleted or severely corrupted, yes. This is why backups are critical. In most cases, the data is fine—it's just a connection issue.

Should I contact my host?

Yes, if:

  • You've checked credentials and they're correct
  • phpMyAdmin doesn't work either
  • Error persists after basic troubleshooting

How do I prevent this?

  1. Use reliable hosting
  2. Keep regular backups
  3. Update WordPress/plugins regularly
  4. Don't over-install plugins
  5. Monitor server resources

The error says my database needs repair. Is that serious?

Usually fixable with the repair function. If repair fails, restore from backup.

Quick Fix Checklist

  1. Check if phpMyAdmin works (is MySQL running?)
  2. Verify wp-config.php credentials match cPanel
  3. Try resetting database user password
  4. Check DB_HOST value is correct
  5. Try database repair
  6. Disable plugins via FTP
  7. Check server resources/disk space
  8. Contact hosting support

Key Takeaways

  1. Usually credential mismatch - Check wp-config.php first
  2. Database server issues - Contact host if credentials are correct
  3. Corruption is fixable - Use WordPress repair or phpMyAdmin
  4. Backups save you - Always have recent backups
  5. Quality hosting helps - Fewer database issues on good hosts

What to Do Next

  1. Run through the checklist above
  2. Contact host support if stuck
  3. Restore from backup if data is corrupted
  4. Consider better hosting if this happens frequently

Having recurring database issues? It might be time to upgrade your hosting. Compare options with our hosting comparison tool or take the hosting quiz for recommendations suited to your needs.


Last updated: January 2026

Share:
HostDuel Team

HostDuel Team

The HostDuel team researches and compares web hosting providers to help you make informed decisions.