How to Change MySQL User Password and Update wp-config.php

55 views
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

  1. Inspect wp-config.php to Find DB User:
    • Open File Manager in cPanel and navigate to public_html.
    • Right-click wp-config.php and click Edit.
    • Note down the values for DB_NAME and DB_USER:
      define('DB_USER', 'cpuser_dbuser');
  2. 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.
  3. Update wp-config.php:
    • Return to the wp-config.php editor in File Manager.
    • Replace the old password inside define('DB_PASSWORD', 'PASTE_NEW_PASSWORD_HERE');.
    • Click Save Changes in the top right.
  4. 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
Was this article helpful?
No, I need more help
Didn't find your answer?
Under 3 minutes
Submit Support Ticket