MySQL8和MySQL5修改密码的sql差别很大,用了MySQL5的修改方法还可能掉坑里面,本文介绍8版本的修改方法
1.登录MySQL
mysql -uroot -p密码
2.切换到user数据库
use mysql;
3.修改密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码';
这个%是要从user数据库里查出来的
select user ,host from user where user='root';
4.刷新就可以了
flush privileges;
5.如果报错 Operation ALTER USER failed for 'root'@'%',需要将user表里一个字段置空再修改才行
update user set authentication_string='' where user='root';