MySQL is a widely used open source database management system with strong performance, reliability and security. When using MySQL, it is often necessary to change the password of the database administrator (or other user) to ensure data security. This article will introduce how to change user passwords in MySQL.
First, you need to log in to MySQL using the correct credentials. You can log in to MySQL using the following command:
mysql -u USERNAME -p
where USERNAME is your username. After executing the command, MySQL will ask you for your password. Enter the password and press Enter to enter MySQL.
In MySQL, you can use the following command to display the current user:
SELECT user, host FROM mysql.user;
This command will display the current user in MySQL list of users. Select the user whose password you want to change in the list.
After you select the user whose password you want to change, you can use the following command to change the password:
ALTER USER 'username'@'host' IDENTIFIED BY 'new_password';
Where, 'username' and 'host' is the username and host address you want to change the password for, and new_password is the new password you want to set. After executing this command, MySQL will update the user's password.
You can also use the following command to change your own password:
SET PASSWORD FOR 'username'@'host' = PASSWORD('new_password');
Similarly, 'username' and 'host' are the username and host address you want to change the password, and new_password is the password you want to set new password. After executing this command, MySQL will update your password.
After you have completed all changes, you can exit MySQL using the following command:
EXIT;
This will exit MySQL and return you to the command line interface.
Summary
MySQL is a powerful database management system that requires regular changes to the administrator password to ensure data security. This article introduces how to change user passwords in MySQL. I hope it will be helpful to you.
The above is the detailed content of How to change mysql password. For more information, please follow other related articles on the PHP Chinese website!