How to change the password: 1. Execute the "mysql -u root -p" command and enter the password to log in to MySQL; 2. Use "set password for username@localhost = password('new password');" statement to change the password.
The operating environment of this tutorial: windows7 system, mysql5.7 version, Dell G3 computer.
When using the database, we may encounter situations where MySQL needs to change the password, such as the password is too simple and needs to be changed, etc. This section mainly introduces 2 methods to modify the MySQL database password.
1. Use the SET PASSWORD command
Step 1): Enter the commandmysql -u root -p
Specify the root user to log in to MySQL, enter Press Enter to enter your password. If no environment variables are configured, please log in to the bin directory of MySQL.
Step 2): Use SET PASSWORD to change the password. The command format isset password for username @localhost = password(newpwd);
, where username is the username to change the password, and newpwd is the password to be changed. Changed new password. as the picture shows.
After changing the password, enter thequit;
command to exit MySQL and log in again, enter the new password "root" to log in;
2. Use mysqladmin to change the password
Use the mysqladmin command to change the MySQL root user password format tomysqladmin -u username -p old password password new password
.
Note: In the command to change the password in the figure below, -uroot and -proot are a whole. Do not write -u root -p root. You can add a space between -u and root, but a warning will appear, so don't Added spaces.
[Related recommendations:mysql video tutorial]
The above is the detailed content of How to change password in mysql5.7. For more information, please follow other related articles on the PHP Chinese website!