"Error establishing a database connection" (WordPress) and similar "could not connect to database" messages from other apps all have the same shortlist of causes. This guide fixes them in order.
The usual causes
- The database name in the app's config doesn't match one in cPanel.
- The database user doesn't exist or isn't a user of that database.
- The password is wrong (or contains a character that got mangled when copied).
- The host is wrong for the plan.
- The user lacks privileges (sometimes ALL isn't granted).
Verify each value in cPanel
- Log into cPanel and open MySQL Databases.
- Under Databases, confirm the exact database name your app uses actually exists (note the account prefix in the name).
- Under Users, confirm the username exists and is listed as having access to that database.
- If the user isn't connected to the database, click Add User to Database, choose the pair, and grant ALL PRIVILEGES.
- Compare these against the values in your app's config file — for WordPress, that's
public_html/wp-config.php(see How to Connect a MySQL Database to WordPress for the four lines to check).
The password trap
If the password contains characters like ', # or ; and it was set through certain tools, the config file may need them escaped — but the safest fix is to reset the MySQL user's password in cPanel and update the config to exactly that new password.
DB_HOST on WebFulHost
Shared hosting uses localhost. If you've ported a site from elsewhere and left a specific hostname or IP in place, switch it back to localhost.
Just restored or migrated?
See the side-effects in What to Check Before Restoring a Backup — restored or copied databases must keep the exact name and user the app expects. If everything above checks out and the error persists past half an hour, contact support to check the MySQL service itself.