How to Fix Error Establishing a Database Connection in WordPress

This error means WordPress cannot reach your database; check credentials, the database host, and corrupted tables.

· Updated · 4,153 views

"Error establishing a database connection" means WordPress loaded but could not connect to MySQL. The cause is almost always wrong credentials, an unreachable database server, or a corrupted database.

Verify Database Credentials

  1. In cPanel, open File Manager and edit wp-config.php.
  2. Confirm these four values match a working database and user:
define( 'DB_NAME', 'user_wpsite' );
define( 'DB_USER', 'user_wpuser' );
define( 'DB_PASSWORD', 'your_password' );
define( 'DB_HOST', 'localhost' );
  1. In MySQL Databases, confirm the user is attached to the database with All Privileges. If unsure, reset the user password and update wp-config.php.

Test the Database Server

If credentials are correct, the MySQL service may be overloaded or down. Open phpMyAdmin in cPanel and try to browse the database. If it loads, the issue is in wp-config.php; if it does not, contact support.

Repair a Corrupted Database

Add this line to wp-config.php:

define( 'WP_ALLOW_REPAIR', true );

Visit yourdomain.co.ke/wp-admin/maint/repair.php and run Repair Database. Remove the line afterwards for security.

| Symptom | Likely cause | |---|---| | Front and admin both broken | Wrong credentials or DB down | | Admin says DB needs repair | Corrupted tables | | Intermittent error | Server overload or too many connections |

If the error persists after these steps, reach out on WhatsApp at +254 796 358081.

Was this article helpful?

Your feedback helps us improve our documentation.

Still Need Help?

Our support team is available 24/7 to assist you.