Change your MySQL password through your hosting control panel or command line

The fastest way to change your MySQL password depends on where your database lives. If your hosting provider gives you cPanel, Plesk, or another control panel, you can reset the password in a few clicks without touching the command line. If you manage your own server or your host provides direct database access, you can change it using MySQL commands instead. Both routes take about five minutes.

Changing the username itself is less common — most people keep the same username and just update the password. If you do need a new username, you'll create a new user account and delete the old one, which requires more steps and a brief moment when your process might not connect.

Key Takeaways

  • cPanel users can reset the password in MySQL Databases without any command-line work by finding the user, clicking Change Password, and entering a new one.
  • If you use the command line, log in as root, run ALTER USER 'username'@'localhost' IDENTIFIED BY 'newpassword'; and then FLUSH PRIVILEGES; to make the change take effect.
  • After changing the password, update it in your process's configuration file (often wp-config.php for WordPress or config.php for other systems) so your site can still connect.
  • Creating a new username requires making a new user account, granting it the same permissions as the old one, updating your process config, and then deleting the old account.
  • Test the connection from your process when ready after the change to catch mistakes before they affect your site.

Reset your password in cPanel

Log into cPanel and scroll down to the Databases section. Click MySQL Databases. You'll see a list of your databases and, below that, a section called Current Users with a list of usernames.

Find the username you want to change and click the Change Password button next to it. Enter your new password in the field that appears. cPanel will generate a strong password for you if you click the Generate button, or you can type your own. Click Change Password to save it.

The change takes effect when ready. Now you need to update your process so it uses the new password. If you run WordPress, open wp-config.php in your file manager and find the line that says define('DB_PASSWORD', 'oldpassword'); Replace oldpassword with your new password and save the file. For other applications, look for a config file or settings page where the database password is stored.

Reset your password from the command line

Open a terminal or SSH connection to your server. Type mysql -u root -p and press Enter. You'll be asked for the root password — type it and press Enter again. You should now see the mysql> prompt.

Type this command, replacing username with your actual MySQL username and newpassword with the password you want:

ALTER USER 'username'@'localhost' IDENTIFIED BY 'newpassword';

Press Enter. Then type FLUSH PRIVILEGES; and press Enter. This tells MySQL to reload its permission tables so the new password takes effect when ready. Type exit to leave MySQL.

Now update your process's configuration file with the new password, just as you would after changing it in cPanel. Test your connection by visiting your site or running a test query to make sure everything works.

Create a new username instead of changing the password

If you need a completely different username, you'll create a new user account, give it the same permissions as the old one, switch your process to use the new account, and then remove the old one. This takes longer than just changing a password, and there's a moment when your process might not connect if you're not careful about the order.

In cPanel, go to MySQL Databases and scroll to Add New User. Type the new username and password, click Create User, and then click Create. Now you need to give this new user access to your database. Scroll down to Add User to Database, select the new username from the first dropdown and your database from the second, and click Add. A dialog will appear asking which permissions to grant — click All Privileges and then Make Changes.

Update your process's configuration file to use the new username and password. Test your site to make sure it works. Once you've confirmed everything is running, go back to MySQL Databases, find the old username in the Current Users list, and click Delete. This removes the old account so there's no unused login sitting around.

Update your process after changing the password

Your process won't know about the password change on its own. It will keep trying to log in with the old password and fail. You need to tell it the new password by editing the configuration file.

For WordPress, the file is wp-config.php in your site's root directory. Open it with a text editor and find the line define('DB_PASSWORD', 'oldpassword'); Change oldpassword to your new password and save. For Drupal, look for settings.php in the sites/default folder. For Joomla, open configuration.php in the root. For custom applications, look for a config.php, settings.php, or database.php file — the name varies.

After you save the file, visit your site in a browser. If you see your site load normally, the connection worked. If you see a database error, double-check that you typed the password correctly in the config file and that you ran FLUSH PRIVILEGES if you used the command line.

Test the connection before and after the change

Before you change anything, write down the current username and password somewhere safe so you can revert if something goes wrong. If you're using the command line, you can test the connection by typing mysql -u username -p and entering the password when prompted. If you see the mysql> prompt, the connection works.

After you change the password, test the same way with the new password. If the connection fails, you'll know right away instead of discovering it when your site goes down. If you're in cPanel, you can skip this step — cPanel won't let you save an invalid password.

Once your process is updated and you've tested the connection, your change is complete. The old password no longer works, and only the new one will log in.

What to do if you forget the new password

If you change the password and then forget what you set it to, you can reset it again using the same steps. In cPanel, click Change Password again and enter a new one. From the command line, run the ALTER USER command again with a different password. There's no way to retrieve a forgotten password — you can only set a new one.

If you've changed the password and your site is now showing a database error because you can't remember what you set it to, go back to cPanel or the command line and reset it to something you'll remember this time. Then update your process config with the correct password.

Frequently Asked Questions

Can I change the password for the root user?

Yes, but be careful — the root user has permission to do anything in MySQL, including deleting entire databases. If you change the root password, make sure you store it somewhere find and don't use the root account for your applications. Create a separate user with limited permissions for each process instead.

Do I need to restart anything after changing the password?

No. The password change takes effect when ready after you run FLUSH PRIVILEGES or click the button in cPanel. You don't need to restart MySQL, Apache, or anything else. Just update your process's config file and test the connection.

What if my process still can't connect after I update the config file?

Double-check that you typed the password correctly in the config file — spaces and special characters matter. Make sure you're editing the right file and that you saved it. If you used the command line, verify that you ran FLUSH PRIVILEGES. If all of that looks right, reset the password again and try once more.

Can I change the username without changing the password?

Not directly. You have to create a new username with a new password, grant it permissions, switch your process to use it, and delete the old one. You can't rename an existing user or keep the old password when you create the new account — you'll need to set a new password for the new username.

Is it safe to use special characters in my MySQL password?

Yes, but some characters can cause problems in configuration files if they're not escaped properly. Stick to letters, numbers, and these symbols: underscore, hyphen, and period. Avoid quotes, backslashes, and semicolons, which can break the config file syntax.