select version();
根据版本号查找下面的修改密码方式
use mysql;
update user set pasword = password("new pasword") where user = "root";
-- 一定要刷新,否则不生效
flush privileges;
mysql 5.7.9以后废弃了password字段和password()函数;
新增了authentication_string字段表示用户密码
而authentication_string字段下只能是mysql加密后的41位字符串密码
所以需要用下面方式来修改root密码
ALTER user 'root'@'localhost' IDENTIFIED BY 'newpassword';
flush privileges;
或者
update user set authentication_string = password("your new password") where user = "userName";
flush privileges;
8.x开始修改密码有了变化,修改密码前先检查authentication_string是否为空
authentication_string非空
use mysql;
-- 将字段置为空
update user set authentication_string='' where user='root';
-- 修改密码为 new pasword
ALTER user 'root'@'localhost' IDENTIFIED BY 'new pasword';
flush privileges;
authentication_string空则直接修改:
-- 修改密码为 new pasword
ALTER user 'root'@'localhost' IDENTIFIED BY 'new pasword';
flush privileges;
8.x版本搞定
重要提示:所有版本更新最后修刷新下!!!
http://blog.xqlee.com/article/2404071334384076.html