1.vi /etc/my.cnf
[mysqld]段落中加上一句:skip-grant-tables保存并退出
2.重启mysql:service mysqld restart
3.进入mysql:mysql -u root
update user set authentication_string='' where user='root';并退出
4.vi /etc/my.cnf
[mysqld]段落中注释:skip-grant-tables保存并退出
5.重启mysql:service mysqld restart
6.再次进入mysql:mysql -u root
6.1.use mysql;
6.2.设置较复杂的新密码:ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码';
6.3.FLUSH PRIVILEGES;