Database connection error - how to fix it (cPanel)
"Error establishing a database connection", "Access denied for user", "Unknown database" mean the site cannot log in to the database with the details stored in its settings.
Where the connection details are
| CMS | File and settings |
|---|---|
| WordPress | wp-config.php: DB_NAME, DB_USER, DB_PASSWORD, DB_HOST |
| Joomla | configuration.php: $db, $user, $password, $host |
| OpenCart | config.php and admin/config.php: DB_DATABASE, DB_USERNAME, DB_PASSWORD |
| Laravel and others | .env: DB_DATABASE, DB_USERNAME, DB_PASSWORD |
Check in order
- The database and user names are full, with the account prefix (
example_shop). Compare with "Manage My Databases". - The user is added to the database. In "Current Databases" the user must be listed under "Privileged Users".
- The password. If unsure, set a new password for the user ("Change Password" in the user list) and put it in the settings file.
- The host is
localhost.

If the database has no user, add one with "ALL PRIVILEGES": databases in cPanel, steps 7-10.
After moving a site from another host, the database and user names are almost always different - change them in the settings file. If something does not work, contact support from your client area (Tickets).