一、基本思路
1、修改配置文件,跳过密码检查
2、修改MySQL密码
二、具体操作
1、修改配置文件
在/etc/my.cnf
文件的[mysqld]
模块中增加skip-grant-tables
vim /etc/my.cnf
修改完成后,重启MySQL
服务以载入配置文件
systemctl restart mysqld
2、修改root密码
使用update
关键字进行密码更新
## 登录MySQL
mysql
## 更新密码
update mysql.user set authentication_string=password('新密码') where user='root';
## 更新权限
flush privileges;
## 退出
quit
3、恢复密码检查
删除在配置文件中增加的skip-grant-tables
,然后重启MySQL服务
systemctl restart mysqld