1. 停止mysql服务:
systemctl stop mysqld
2. 使用跳过授权表的方式启动数据库
mysqld_safe --skip-grant-tables --user=mysql &
3. 匿名登录
mysql -uroot -p
4. 修改user表
注意:mysql5.7的user表中的password字段已经改成了authentication_string 字段了
进入mysql库:
use mysql;
重置密码:
update user set authentication_string = password("123456") where user='root' and host='localhost';
刷新数据库:
flush privileges;
5. 重启mysql服务
systemctl start mysqld