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

旧版的 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; 再输入上面修改密码的指令,就能成功了.

具体操作流程如下[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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值