【Mysql】Mysql修改Root密码

1、用命令编辑/etc/my.cnf配置文件,即:vim /etc/my.cnf 或者 vi /etc/my.cnf 或者 nano /etc/my.cnf

2.在[mysqld]下添加skip-grant-tables,然后保存并退出

3.重启mysql服务:service mysql restart

4、重启以后,执行mysql命令进入mysql命令行

5、修改root用户密码

MySQL> UPDATE mysql.user SET Password=PASSWORD('新密码') where USER='root';

     5.7版本已经没有password字段了需要修改为

  UPDATE mysql.user SET authentication_string =PASSWORD('新密码') where USER='root';

MySQL> flush privileges;
MySQL> exit

6、最后把/etc/my.cnf中的skip-grant-tables注释掉,然后重启mysql

mysql5.7 明明已经设置好密码,但还是提示要设置重置密码: PS还是5.7

错误:You must reset your password using ALTER USER statement before executing this statement.

解决办法:

step 1:SET PASSWORD = PASSWORD('your new password');

step 2:ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

step 3:flush privileges;

原文地址:https://www.cnblogs.com/mqxs/p/9782347.html