1  修改配置文件

vim /etc/my.cnf

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

[mysqld] 

skip-grant-tables    #添加此条配置,用来跳过授权表

2 重启数据库 

systemctl restart mysqld

3 设置新密码

mysql5.6

update user set password=PASSWORD('新密码') where user='root';

mysql5.7

update user set authentication_string = password('新密码') where user = 'root';

或者
update user set authentication_string = password('新密码'), password_expired = 'N', password_last_chang_changed = now() where user = 'root';

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄