The operating environment of this tutorial: windows7 system, mysql5.7.12 version, Dell G3 computer.
In mysql, you can log in to the root account and use root to change the password of an ordinary user.
The root user has very high permissions and can not only change his own password, but also change the passwords of other users.
mysql5.7.12 Steps to change user password
1. Use the "win r" key to open the "Run" window and enter "cmd" and press Enter to open the cmd window
2. In the cmd window, execute "mysql -u root -p" command and enter the password to log in to the MySQL database as root
3. In the mysql command mode, use the SET statement to modify Password for ordinary users
In MySQL, only the root user can change the password by updating the MySQL database. After logging in to the MySQL server as the root user, you can use the SET statement to modify the ordinary user password. The syntax format is as follows:
SET PASSWORD FOR 'username'@'hostname' = PASSWORD ('newpwd');
Among them, the username parameter is the user name of an ordinary user, the hostname parameter is the host name of an ordinary user, and newpwd is the new password to be changed.
Note: The new password must be encrypted using the PASSWORD() function. If it is not encrypted using PASSWORD(), it will be executed successfully, but the user will not be able to log in.
If an ordinary user changes the password, you can omit the FOR clause to change your own password. The syntax format is as follows:
SET PASSWORD = PASSWORD('newpwd');
For example: Use the SET statement to change the password of the testuser user to "newpwd"
SET PASSWORD FOR 'testuser'@'localhost' = PASSWORD("newpwd");
It can be seen from the running results that SET The statement is executed successfully, and the password of the testuser user is successfully set to "newpwd".
The following verifies whether the password of the testuser user has been modified successfully. Exit the MySQL server, log in as the testuser user, and enter the password "newpwd"
mysql -utestuser -p
It can be seen from the running results that the testuser user logged in successfully and changed the password successfully.
[Related recommendations:mysql video tutorial]
The above is the detailed content of How to change user password in mysql5.7.12. For more information, please follow other related articles on the PHP Chinese website!