First, MySQL change Password method:
1. Modify with Mysqladmin
#mysqladmin-uroot-p password ' newpass ' Enter password: note: If it is the first time to change the password, prompt enter password: Direct carriage return if it is reset password, prompt enter Passwor D: Enter the old password and return
2. Enter MySQL for password modification
mysql> set password for ' root ' @ ' 127.0.0.1 ' =password (' newpasswd '), or so:mysql> set password for ' root ' @ '% ' = Password (' newpasswd ');
3. Edit the user table using update
mysql> Update user Set Password=password (' NewPassword ') where user= ' root ' and host= ' localhost ';mysql> flush privileges; Note: Do not forget to execute the flush privileges command!
Second, MySQL forgot how to deal with the password
Description: In the case of MySQL running
1, under/ETC/MY.CNF [mysqld] Add skip-grant-tables Restart the MySQL process, restart the successful, directly execute #mysql can enter MySQL, and then modify the:mysql> use Mysqldatabase changedmysql> Update user set Password=password (' NewPassword ') where user= ' root ' and host= ' localhost '; Query OK, 1 row affected (0.01 sec) Rows matched:1 changed:1 warnings:0mysql> flush privileges; Query OK, 0 rows affected (0.05 sec) Note: Only the modified mode of update can be used, the set mode cannot be modified successfully in Skip-grant-tables mode! 2, remove the skip-grant-tables from the my.cnf, restart the MySQL process, you can use the new password to enter MySQL.
This article is from the "Knowledge System" blog, please be sure to keep this source http://linuxg.blog.51cto.com/4410110/1895967
MySQL database several ways to change the password and forgot password processing method