Sometimes, in the test environment to forget the root password of MySQL, retrieve or change the password is critical!
01, can use root to enter the database
Mysql-u Root
Mysql> SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' Newpass '); # # #修改root密码, change the root password to Newpass
Flush privileges;
03: Edit the user table directly with Update # # #前提是root可以使用
Mysql-u Root
mysql> use MySQL;
mysql> UPDATE user SET Password = Password (' newpass ') WHERE user = ' root ';
mysql> FLUSH privileges;
04. When the root password is lost
Execute directly under the shell and close the shell directly after modification
Mysqld_safe--skip-grant-tables # # #不效验登录密码, can be password-free login,
mysql> user MySQL
mysql> UPDATE user SET Password=password ("New password") WHERE user= ' root ';
mysql> FLUSH privileges;
Ps-ef | grep MySQL | Grep-v grep | awk ' {print $} ' | Xargs kill-9 # # #杀掉mysql进程
Reproduced:
Http://pengbotao.cn/mysql-modify-password.html
MySQL Change root password