1 关闭mysql 服务
systemctl stop mysqld
2 . 修改mysql 配置文件,跳过密码登录
echo skip-grant-tables >> /etc/my.cnf
3 . 开启mysql 服务,并登录mysql (不需要密码)
mysql
4 . 更改mysql系统中user表中登录用户的密码
--使用mysql 数据库
use mysql
--更新密码
--update user set password=password("要更改的密码") where user="更改的用户名";
--注意版本区别,在新版本中 提示没有这个password 字段,密码字段是authentication_string
--update user set authentication_string=password("要更改的密码") where user="更改的用户名";
update user set authentication_string=password("root") where user="root";
--刷新权限
flush privileges;
5 . 还原配置文件,并重启服务并登录
--将刚才修改的 mysql配置文件还原,删除最后一行,vi /etc/my.cnf
skip-grant-tables
--重启mysql 服务
systemctl restart mysqld
--使用新密码登录mysql
mysql -uroot -proot