Wordpress info

How to Fix ‘Error Establishing Database Connection’ in WordPress

Table of Contents

The “Error establishing a database connection” message means WordPress can’t communicate with your MySQL database. Unlike WSoD, this error is explicit — and fixable. The cause is usually incorrect credentials, a corrupted database, or a down server.

Common Causes

  • Wrong credentials in wp-config.php (most common)
  • Database server down (hosting issue)
  • Corrupted database tables
  • Exceeded database quota on shared hosting
  • Recent migration with wrong settings

Step 1: Verify Database Credentials

Open wp-config.php and check these four values:

DB_NAME, DB_USER, DB_PASSWORD, DB_HOST

Log into your hosting control panel, open the database section, and confirm the name, username, and password match exactly. DB_HOST is usually “localhost” but some hosts use a remote address.

Step 2: Test the Database Server

If credentials are correct, the server may be down. Contact your host or check their status page. On shared hosting, database connections can be temporarily unavailable during high load. Wait and retry, or ask support to restart MySQL.

Step 3: Repair the Database

Add to wp-config.php: define('WP_ALLOW_REPAIR', true); Then visit yourdomain.com/wp-admin/maint/repair.php. Choose “Repair and Optimize”. Remove the define line afterward for security.

Step 4: Check Database Quota

Shared hosts often limit database size. If you’ve hit the quota, WordPress can’t write. In your hosting panel, check database usage. Delete unused tables or upgrade your plan.

Frequently Asked Questions

Why did this happen after a plugin update? Some plugins modify the database. A failed update can corrupt tables. Repair the database and update the plugin on a staging site first next time.

Can I prevent this error? Keep credentials documented, maintain backups, and avoid hitting database quotas. Use a reliable host with good MySQL uptime.

Is my data lost? Almost never. The database usually exists; WordPress just can’t connect. Once credentials or server issues are resolved, data returns intact.

Conclusion

This error is scary but rarely catastrophic. Check credentials first (90% of cases), then repair the database, then verify the server. Keep a backup so you’re never at the mercy of a database failure. Your data is almost certainly safe.