1. 关闭数据库
/etc/init.d/mysqld stop
2. 安全模式启动数据库
[root@localhost data]# mysqld_safe --skip-grant-tables --skip-networking &
3. 登陆数据库
mysql
4. 刷新授权表
flush privileges;
5. 修改密码
mysql> alter user root@'localhost' identified with mysql_native_password by
'123';
6. 重启数据库到正常模式
[root@localhost data]# /etc/init.d/mysqld restart