Home > Database > Mysql Tutorial > How to change user password in mysql5.7.12

How to change user password in mysql5.7.12

青灯夜游
Release: 2022-06-27 17:50:20
Original
19975 people have browsed it

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

How to change user password in mysql5.7.12

How to change user password in mysql5.7.12

2. In the cmd window, execute "mysql -u root -p" command and enter the password to log in to the MySQL database as root

How to change user password in mysql5.7.12

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');
Copy after login

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');
Copy after login

For example: Use the SET statement to change the password of the testuser user to "newpwd"

SET PASSWORD FOR 'testuser'@'localhost' = PASSWORD("newpwd");
Copy after login

How to change user password in mysql5.7.12

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
Copy after login

How to change user password in mysql5.7.12

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template