Change a MySQL User Password
Changing MySQL passwords to something new and secure is easy via the command line.
If you have created MySQL users to help you organize your database management, you might need to change user passwords for security reasons. If you’re comfortable with the command line, it only takes a few minutes to change MySQL user passwords.
Using Command Line to Change MySQL Passwords
- Using the terminal program of your choice, log into your server as root. If you haven’t logged into your server using the command line before, read Logging into Your Server via Secure Shell (SSH) first.
- Now you’ll log into your MySQL server by typing
mysql -u root -p
Then press Enter. The -u root flag tells MySQL you want to log in as the root user, and the -p flag prompts MySQL to ask you for a password. When prompted, enter your root password and press Enter.
- You’ll now see a MySQL prompt that looks like
mysql>
- All the user data is stored in its own table in MySQL. So, navigate to the table by typing
USE mysql;
- Then press Enter.
- Now you’ll update the row where the user information is stored using this syntax:
UPDATE user SET Password=PASSWORD('password1') WHERE user='username';- Replace “password1” with the new password.
- Replace “username” with the username that needs a new password.
Then press Enter.
- You’ve successfully changed your user’s password!