MySQL新版本密码_新版mysql重置root密码

疯一样的男子
疯一样的男子
发布于 2021-08-11 / 1 阅读
0
0

MySQL新版本密码_新版mysql重置root密码

旧版的 mysql 数据库我们可以通过以下MySQL命令来重置密码

  update MySQL.user set authentication_string=password('xxxxxxxxxxx') where user='root';

新版 mysql ,通过以上方式重置密码,并不会生效

正确做法是,停止 mysqld 服务,通过执行下面的代码启动服务

  mysqld_safe --skip-grant-tables 

然后新打开一个终端里输入 mysql 直接进入,这时候执行

  ALTER user 'root'@'localhost' IDENTIFIED BY 'xxxxxxxxxxx';

或者

  SET PASSWORD FOR root = PASSWORD("xxxxxxxxxxx");

来重置密码,不过直接这么输入会可能会报错

ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement

最最关键的是, 需要先输入

  flush privileges;

再输入上面修改密码的指令,就能成功了。

具体MySQL命令操作流程如下

[root@centos7 wwwroot]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.3.16-MariaDB-log Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> ALTER user 'root'@'localhost' IDENTIFIED BY 'xxxxxxxxxxx';
ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> ALTER user 'root'@'localhost' IDENTIFIED BY 'xxxxxxxxxxx';
Query OK, 0 rows affected (0.000 sec)


评论