This either means that the username and password information in your wp-config.php file is incorrect or that contact with the database server at localhost could not be established. This could mean your host’s database server is down.
The WordPress error:
“Error establishing a database connection”
means WordPress can’t connect to your MySQL database. This is almost always caused by one of these 5 issues.
✅ Step-by-Step Fix
1️⃣ Check Your wp-config.php Credentials (Most Common Issue)
Open your wp-config.php file (in your WordPress root folder).
Look for:
define('DB_NAME', 'database_name');
define('DB_USER', 'database_username');
define('DB_PASSWORD', 'database_password');
define('DB_HOST', 'localhost');
✔ Verify:
- Database name is correct
- Username is correct
- Password is correct
- DB host is correct
🔎 Where to confirm?
Log into your hosting control panel (cPanel / Plesk / hosting dashboard) → MySQL Databases → confirm:
- Database exists
- User exists
- User is assigned to database
- Password matches
If unsure, reset the database user password and update wp-config.php.
2️⃣ Confirm the Database Server Host
Most hosts use:
localhost
But some use something different, like:
127.0.0.1mysql.yourdomain.com- A specific IP address
Check your hosting provider documentation or ask support.
If you’re on managed WordPress hosting (like WP Engine or SiteGround), the DB host is often not localhost.
3️⃣ Check If MySQL Server Is Down
Try creating a file called test.php in your WordPress root:
<?php
$link = mysqli_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysqli_connect_error());
}
echo 'Connected successfully';
?>
Replace credentials.
If it fails → database server is likely down.
Contact your hosting provider.
4️⃣ Check If Database Is Corrupted
Add this line to wp-config.php:
define('WP_ALLOW_REPAIR', true);
Then visit:
yourdomain.com/wp-admin/maint/repair.php
Run repair.
After finishing, remove the line from wp-config.php.
5️⃣ Check If You’ve Hit Hosting Limits
On shared hosting:
- Too many connections
- Memory limit reached
- Server overload
Check your hosting dashboard → resource usage.
6️⃣ If This Happened After Migration
Common causes:
- Wrong DB host
- Forgot to import database
- Database user not assigned
- Old credentials in
wp-config.php
If you migrated manually or via plugin, re-check:
- Database imported successfully
wp-config.phpupdated
🔎 Quick Diagnosis Table
| Situation | Most Likely Cause |
|---|---|
| Frontend broken but admin works | Corrupted database |
| Both broken immediately after moving site | Wrong DB credentials |
| Random intermittent error | Server overload |
| Just changed password | wp-config.php not updated |
⚡ Fastest Fix (90% of cases)
- Reset database user password
- Reassign user to database
- Update
wp-config.php - Save
- Refresh site




