mysql5.7 修改root密码方法

in mysql with 0 comment

由于mysql5.7密码字段已取消password字段,改成了新的"authentication_string".因此修改密码的命令需要变更如下:

首先登录mysql,切换到mysql库,然后执行修改命令,最后要刷新下权限.


MySQL [mysql]> use mysql;

MySQL [mysql]> update user set authentication_string=password('m@4hCw9UN97WiV&x') where user='root';
Query OK, 2 rows affected, 1 warning (0.01 sec)
Rows matched: 2  Changed: 2  Warnings: 1

MySQL [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

以下是mysql5.6版本的修改密码方式:

mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD('新密码') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;

如果忘记root密码,可以用这种方式:

mysqld_safe --skip-grant-tables&
mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("新密码") WHERE user='root';
mysql> FLUSH PRIVILEGES;
Responses