修改MySQL root 用户密码:
编辑配置文件 /etc/my.cnf
,在 mysqld
下添加 skip-grant-tables
:
[mysqld]
skip-grant-tables
重启MySQL服务:
[root@JT-T-KEYAN-001 ~]# service mysqld restart
Shutting down MySQL.... [确定]
Starting MySQL. [确定]
[root@JT-T-KEYAN-001 ~]#
直接输入 mysql
进入
[root@JT-T-KEYAN-001 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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>
切换到 mysql 数据库:
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>
修改密码并退出:
mysql> update user set authentication_string=password('your_password') where user = 'root';
Query OK, 2 rows affected, 1 warning (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> exit
Bye
[root@JT-T-KEYAN-001 ~]#
删除配置文件中添加的skip-grant-tables
,重启MySQL服务:
[root@JT-T-KEYAN-001 ~]# service mysqld restart
Shutting down MySQL.. [确定]
Starting MySQL. [确定]
[root@JT-T-KEYAN-001 ~]#