修改my.cnf配置 sed -i ‘/mysqld/askip-grant-tables’ /etc/my.cnf
重启mysql
systemctl restart mysqld
进入mysql
这次就不需要root密码了
use mysql;
UPDATE user SET Password = password('newpassword') where User = 'root';
刷新权限: flush privileges
退出:quit
还原my.cnf配置sed -i 's/skip-grant-tables/#skip-grant-tables/g' /etc/my.cnf
再次重启mysql服务:systemctl restart mysqld