Changing Your Database Password
Changing your database password periodically is a good security practice. It is also necessary if you suspect your credentials have been compromised. This guide shows you how to safely change your database password without breaking your website.
Step 1: Change the Password in cPanel
- Log in to cPanel and navigate to MySQL Databases.
- Scroll down to the Current Users section.
- Find the database user whose password you want to change and click Change Password.
- Enter a new strong password. Use the Password Generator to create a secure password with a mix of uppercase, lowercase, numbers, and special characters.
- Click Change Password to save.
Step 2: Update Your Website Configuration
After changing the password in cPanel, you must update the password in your website's configuration file. If you skip this step, your website will immediately show a database connection error.
WordPress
Edit the wp-config.php file in your website root directory:
define('DB_PASSWORD', 'your_new_password_here');
Joomla
Edit the configuration.php file:
public $password = 'your_new_password_here';
Laravel
Edit the .env file:
DB_PASSWORD=your_new_password_here
Custom PHP Applications
Locate your database connection file, which is often named something like config.php, database.php, or db.php. Find the password variable and update it to the new password.
Step 3: Test Your Website
After updating both cPanel and your configuration file, visit your website to confirm it is working correctly. Check both the front end and admin area to ensure the database connection is functioning.
Password Security Tips
- Use a password that is at least 16 characters long.
- Never use the same password for your database and your cPanel login.
- Store your database password securely and never share it publicly.
- Change your database password immediately if you suspect a security breach.