修改密码网上好多方法都报error 1396。可能是mysql8的原因吧?
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
这里有几个关键命令,最主要就是关闭安全模式
-- 查询一下安全模式开关
show variables like 'sql_safe_updates';
-- 关闭安全模式
set sql_safe_updates = 0;
-- 关闭安全模式下,才可以执行authentication_string为空
update user set authentication_string='' where user='root';
-- authentication_string空了的情况下,才可以真正修改密码
-- 刷新权限表
flush privileges;
-- 修改密码
alter user 'root'@'%' identified by 'yourpassword';
alter user 'root'@'localhost' identified by 'yourpassword';
-- 上面两个二选一,具体参考下面,一一对应
select user, host from user;
附录:
-- 修改密码强度
show variables like 'validate%';
set global validate_password.length = 4;
set global validate_password.policy = LOW;