0
点赞
收藏
分享

微信扫一扫

MySQL数据库root密码恢复

他说Python 2021-09-24 阅读 42
数据库
  1. 停止MySQL服务
  2. 跳过授权表启动MySQL服务程序
  3. 修改root密码
  4. 以正常方式重启MySQL服务程序
示例:
# 停止MySQL服务
[root@node10 ~]# systemctl stop mysqld

# 修改配置文件,跳过授权表启动MySQL服务程序
[root@node10 ~]# vim /etc/my.cnf
[mysqld]
skip-grant-tables
... ...

# 启动服务
[root@node10 ~]# systemctl start mysqld

# 修改root密码
[root@node10 ~]# mysql
mysql> update mysql.user set authentication_string=password('123456')
    -> 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;
Query OK, 0 rows affected (0.01 sec)

# 以正常方式重启MySQL服务程序
[root@node10 ~]# systemctl stop mysqld
[root@node10 ~]# vim /etc/my.cnf
[mysqld]
# skip-grant-tables
... ...
[root@node10 ~]# systemctl start mysqld
[root@node10 ~]# mysql -uroot -p123456
举报

相关推荐

0 条评论