mysql 5.7.9以后废弃了password字段和password()函数;
authentication_string:字段表示用户密码,而authentication_string字段下只能是mysql加密后的41位字符串密码。
所以需要用下面方式来修改root密码:
ALTER user 'root'@'localhost' IDENTIFIED BY 'newpassword';
MySql 从8.0开始修改密码有了变化,在user表加了字段authentication_string,修改密码前先检查authentication_string是否为空
authentication_string非空
use mysql; -- 将字段置为空 update user set authentication_string='' where user='root'; -- 修改密码为root ALTER user 'root'@'localhost' IDENTIFIED BY 'root';
authentication_string空则直接修改:
-- 修改密码为root ALTER user 'root'@'localhost' IDENTIFIED BY 'root';
8.x版本搞定
之前的旧版本修改密码参考:
use mysql; update user set authentication_string = password("root") where user = "root";
https://www.leftso.com/article/2404071334384076.html