30.7.5 忘记root密码的解决方案
修改用户密码中,有一种特殊的情况就是忘记root账户的密码时,如何修改root账户的密码,本节就简单介绍下忘记root账户密码的解决方案。
(1)编辑MySQL的配置文件my.conf,在[mysqld]下添加skip-grant-tables=1配置项,使MySQL在启动时不进行密码验证。
[root@binghe150 ~]# vim /data/mysql/conf/my.cnf [mysqld] skip-grant-tables=1
保存后退出vim编辑器。
(2)重新启动MySQL服务。
[root@binghe150 ~]# service mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK ]
(3)使用root账户登录MySQL。
[root@binghe150 ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 12 Server version: 8.0.18 binghe edition Copyright (c) 2000, 2019, Oracle and/or its affiliates.



