为何mysql不使用skiplist_MySQL忽略授权表方式<--skip-grant-tables>重置管理用户密码

1.管理员用户密码忘记?PS: 一般不会忘记(>﹏

[root@centos7-db01 ~]# mysql -uroot -p

Enter password:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

2.关闭数据库

[root@centos7-db01 ~]# cat /etc/redhat-release

CentOS Linux release 7.4.1708 (Core)

[root@centos7-db01 ~]# systemctl stop mysqld

[root@centos7-db01 ~]# systemctl is-active mysqld

inactive

PS:使用sys-v方式也可以管理数据库服务。

3.启用数据库维护模式

[root@centos7-db01 ~]# mysqld_safe --skip-grant-tables --skip-networking &

[1] 2268

[root@centos7-db01 ~]# ps -ef|grep [m]ysqld_safe

root 2268 1429 0 17:39 pts/0 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --skip-grant-tables --skip-networking

PS:参数查看方式 mysqld --verbose --help|egrep 'skip-grant-tables|skip-networking'。

说明:

--skip-grant-tables :跳过授权表

--skip-networking :跳过远程登录

只允许本地登录,防止在重置密码期间,用户通过远程登录数据库,篡改数据记录、修改授权表信息等操作。

4.登录并修改密码

方式1:

[root@centos7-db01 ~]# mysql

mysql> alter user root@'localhost' identified by '123';

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

mysql> flush privileges;

mysql> alter user root@'localhost' identified by '123';

Query OK, 0 rows affected (0.00 sec)

PS: flush privileges; 加载授权表,使其管理员拥有更改用户密码的权限。

方式2:

[root@centos7-db01 ~]# mysql

mysql> update mysql.user set authentication_string=password('123') where user='root' and host='localhost';

Query OK, 1 row affected, 1 warning (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 1

mysql> flush privileges;

PS: MySQL5.7 版本使用authentication_string字段保存用户密码。

5.关闭数据库,正常启动验证

[root@centos7-db01 ~]# mysqladmin shutdown

[root@centos7-db01 ~]# systemctl start mysqld

#忽略授权表方式登录

[root@centos7-db01 ~]# mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

#原密码登录

[root@centos7-db01 ~]# mysql -uroot -p123456

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

#新密码登录

[root@centos7-db01 ~]# mysql -uroot -p123 -e 'select version();'

mysql: [Warning] Using a password on the command line interface can be insecure.

+-----------+

| version() |

+-----------+

| 5.7.22 |

+-----------+

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值