Programme one:
1. Stop MySQL
Service MySQL Stop
2. Add parameters to MySQL config file '/usr/local/mysql/my.cnf '
--skip-grant-tables
3. Start MySQL
Service MySQL Start
4. Execute a command to enter MySQL
Mysql
5. Update password Note This is the way to mysql5.7.
Mysql>update Mysql.user Set Authentication_string=password (' 123456 ') where user= ' root ' and Host = ' localhost ';
5.7之前的应该这样改: update user set password=password("123") where user="root";
6. Remove the configuration file add parameter '--skip-grant-tables ', restart MySQL, OK
Scenario Two:
Reference: http://www.jb51.net/article/77858.htm
1[[email protected] ~]# service MySQL stop
2[[email protected] ~]# mysqld_safe--skip-grant-tables &
3[[email protected] ~]# mysqld_safe--skip-grant-tables--skip-networking &
4[[email protected] ~]# mysql-p
5mysql> Update Mysql.user Set Authentication_string=password (' 123qwe ') where user= ' root ' and Host = ' localhost ';
6mysql> flush Privileges;
Mysql> quit;
7[[email protected] ~]# service MySQL restart
mysql5.7 forgot root password perfect solution