"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
- In cPanel, open File Manager and edit
wp-config.php. - 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' );
- 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.