"Error establishing a database connection" means WordPress can't reach the MySQL database that holds your content. Most of the time the cause is a single wrong value in wp-config.php, and it takes a few minutes to fix.
Common causes
- Wrong connection details:
wp-config.phpwasn't updated after a migration or password change. - User not linked to the database: the database user exists but was never added to the database with privileges.
- Corrupted tables: an interrupted operation or a plugin bug damaged the tables.
- Resource limits: during a traffic spike the account hits its limits and can't open new connections.
- Server-side issue: rarely, a problem with the MySQL service itself.
Before you start
- Your cPanel login (in the activation e-mail or under Client Area > My Services in the service details).
- Download a copy of
wp-config.phpbefore you change anything.
Step-by-step fix
- Check the connection details. In cPanel open
wp-config.phpin your site folder with File Manager and look at these four lines:
define( 'DB_NAME', 'cpuser_wp' );
define( 'DB_USER', 'cpuser_wpuser' );
define( 'DB_PASSWORD', '********' );
define( 'DB_HOST', 'localhost' );
- Compare the names with cPanel. On the MySQL Databases page, check the database and user names match exactly. In cPanel they carry a prefix starting with your account username (e.g.
cpuser_). Forgetting the prefix is the most common mistake. - Check privileges. Under Add User To Database on the same page, add the user to the database and select ALL PRIVILEGES. Skip this if it's already linked.
- Reset the password. If you aren't sure it's right, use Change Password for the user under Current Users and put the same password in the
DB_PASSWORDline. - Check
DB_HOST. On our hosting accounts the database is on the same server, so the value should belocalhost. Replace any custom host left over from your previous provider. - Save the file and reload your site.
If the details are correct: repair the tables
If the details are right but the error persists, or the admin area says one or more tables are unavailable, the tables may be corrupted.
- In cPanel, use Repair Database on the MySQL Databases page.
- Or temporarily add
define( 'WP_ALLOW_REPAIR', true );towp-config.phpand openhttps://example.com/wp-admin/maint/repair.php. Remove the line as soon as you're done, otherwise the repair page stays open to everyone.
Export a database backup from phpMyAdmin before repairing. For serious corruption, restoring the last good backup is the safest option.
If the error comes and goes
If it only appears at busy times, you're most likely hitting resource limits. cPanel's Resource Usage screen shows when limits were reached. Enabling a cache plugin, removing heavy plugins and limiting bot traffic is usually enough. If the load is constant, consider upgrading your plan.
Troubleshooting summary
| Symptom | Likely cause | Fix |
|---|---|---|
| Error right after a migration | wp-config has old details | Enter the new database name, user and password. |
| Error after a password change | DB_PASSWORD not updated | Write the new password into wp-config. |
| Table warning only in the admin area | Corrupted table | Repair with Repair Database or WP_ALLOW_REPAIR. |
| Intermittent error | Resource limits | Use caching and check Resource Usage. |
| Every site on the account fails at once | Possibly a server-side issue | Open a support ticket. |
Frequently asked questions
Does this error mean my data is gone?
No. It means WordPress can't connect; the data is usually still there. Once the connection is fixed, the site loads as before.
Where do I find my database name?
It's on the DB_NAME line in wp-config.php. Compare it with the list on cPanel's MySQL Databases page.
What if the error doesn't go away?
Open a support ticket from the Client Area and list the steps you've already checked. Our team will look at the server side.
See our cPanel guides for related issues or contact us. Plans built for WordPress are on the WordPress Hosting page.