1 关闭MySQL数据库
[root@db1 ~
]
或者:
[root@db1 ~
]
[root@db1 ~
]
2 使用安全模式启动MySQL数据库
1)–skip-grant-tables 跳过授权表 2)–skip-networking 跳过TCP/IP连接
[root@db1 ~
]
或者;
[root@db1 ~
]
[root@db1 ~
]
3 修改root管理员密码
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
4 手工加载授权表到内存
mysql
> flush privileges
;
Query OK, 0 rows affected
(0.00 sec
)
mysql
> alter user root@
'localhost' identified by
'123';
Query OK, 0 rows affected
(0.00 sec
)
5 重启数据库到正常模式
[root@db1 ~
]
[root@db1 ~
]
ERROR 1045
(28000
): Access denied
for user
'root'@
'localhost' (using password: NO
)
[root@db1 ~
]
mysql:
[Warning
] Using a password on the
command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with
; or \g.
Your MySQL connection
id is 4
Server version: 5.7.28 MySQL Community Server
(GPL
)
Copyright
(c
) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type
'help;' or
'\h' for help. Type
'\c' to
clear the current input statement.
mysql
> show grants
;
+---------------------------------------------------------------------+
| Grants
for root@localhost
|
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO
'root'@
'localhost' WITH GRANT OPTION
|
+---------------------------------------------------------------------+
1 row
in set (0.00 sec
)