Short answer: Change the database user password in cPanel MySQL Databases, then open wp-config.php via File Manager and update the DB_PASSWORD directive to restore database connectivity.
Fix 'Error Establishing a Database Connection' caused by mismatched credentials by resetting your MySQL user password and updating wp-config.php.
Before you start: Back up your site files and database and download the backup to your own computer. How to take a full backup
Quick reference
| Config File | public_html/wp-config.php |
|---|---|
| Critical Line | define('DB_PASSWORD', 'your_new_password'); |
| Tool Location | cPanel > Databases > MySQL Databases > Current Users |
Steps
- Inspect wp-config.php to Find DB User:
- Open File Manager in cPanel and navigate to
public_html. - Right-click
wp-config.phpand click Edit. - Note down the values for
DB_NAMEandDB_USER:define('DB_USER', 'cpuser_dbuser');
- Open File Manager in cPanel and navigate to
- Reset Password in cPanel:
- Go to cPanel > MySQL Databases.
- Scroll to Current Users at the bottom.
- Find your matching user and click Change Password.
- Generate a strong password, copy it, and click Change Password.
- Update wp-config.php:
- Return to the
wp-config.phpeditor in File Manager. - Replace the old password inside
define('DB_PASSWORD', 'PASTE_NEW_PASSWORD_HERE');. - Click Save Changes in the top right.
- Return to the
- Test Website: Refresh your website in your browser. The connection will be restored immediately.
Troubleshooting and tips
- Quotes Syntax Error: Ensure you do not accidentally erase the single quotes surrounding the password (e.g.
'mypassword'). Erasing quotes triggers a fatal PHP syntax error.
Need more help? If you run into an error while following these steps, open a ticket with technical support and our team will look into it. Open a ticket