修改MySQL密码5.7及以上版本(centos7)

在/etc/my.cnf文件中加入skip-grant-tables,让mysql可以免密码登录

之后分别执行如下语句完成密码修改:

mysql> use mysql;

mysql> update user set authentication_string=password("NewPassword") where user="root";

mysql> alter user "root"@"localhost" identified by "NewPassword";

mysql> flush privileges;

退出重启mysql服务

systemctl restart mysqld

修改完成

 

 

如果出现"ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement." 错误,则需要用  ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword' PASSWORD EXPIRE NEVER;  使密码永不过期。

你可能感兴趣的:(修改MySQL密码5.7及以上版本(centos7))