1、在/etc/my.cnf 空文件中加两行配置
[mysqld]
skip-grant-tables
2、重启mysql
systemctl restart mysql.service
重启后直接输入mysql进入数据库
先将密码设置为空
update user set authentication_string='' where user='root';
flush privileges;
3、将my.cnf文件中的配置去掉,重启mysql 。
4、登录数据库后输入如下命令
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码';