美文网首页
MySQL数据库root密码恢复

MySQL数据库root密码恢复

作者: 一个小运维 | 来源:发表于2021-06-13 00:19 被阅读0次
  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

相关文章

网友评论

      本文标题:MySQL数据库root密码恢复

      本文链接:https://www.haomeiwen.com/subject/gzqjeltx.html