密码字段存储在authentication_string
1、查询mysql用户的密码
select host,user,authentication_string from user;
![](https://img-blog.csdnimg.cn/img_convert/5ffd778c10d60221155b728bc4c6bea0.png)
2、alter user修改用户的密码
alter user 'zhangsan'@'%' identified by 'zhangsan1';
![](https://img-blog.csdnimg.cn/img_convert/b8eaacd5115b52eb20b0fe3b9f347f72.png)
在my.cnf 文件中配置了default_authentication_plugin参数
default_authentication_plugin=mysql_native_password
所以修改密码也可以如下方式:
alter user 'zhangsan'@'%' identified with mysql_native_password by 'zhangsan123';
![](https://img-blog.csdnimg.cn/img_convert/80e0928b32b9ee3d6822fb4fb2a03b40.png)
3、root用户忘记密码
# 停止mysql数据库服务
systemctl stop mysqld
![](https://img-blog.csdnimg.cn/img_convert/adca1a11178afc55097f8df269ce44a1.png)
# 编辑配置文件 /etc/my.cnf 末尾添加如下
skip-grant-tables
![](https://img-blog.csdnimg.cn/img_convert/047cde32dc1e25064a6ea461b7b96bc3.png)
# 重启MySQL服务
systemctl start mysqld
![](https://img-blog.csdnimg.cn/img_convert/81c76e96cfce6de1bcbe6bc0da843519.png)
# 直接登录MySQL
mysql
# 查看mysql.user 表信息
use mysql;
select host,user,authentication_string from user;
# 把root用户密码清空
update user set authentication_string='' where user='root';
# 刷新权限
flush privileges;
# 重置root用户密码
alter user 'root'@'%' identified by 'root123';
alter user 'root'@'localhost' identified by 'root123';
# 退出MySQ命令行,使用root123重新登录MySQL即可