第1步. 停止mysql进程
[root@nginx-kafka03 ~]# service mysqld stop
Shutting down MySQL.... SUCCESS!
[root@nginx-kafka03 ~]#
第2步、修改mysql配置文件
[root@nginx-kafka03 ~]# vim /etc/my.cnf
按i进入编辑模式,在配置文件里添加skip-grant-tables,编辑完成后,按:wq退出
第3步、重新启动mysql服务
[root@nginx-kafka03 ~]# service mysqld start
Starting MySQL. SUCCESS!
[root@nginx-kafka03 ~]#
第4步、登录mysql ,不输入密码
[root@nginx-kafka03 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
root@(none) 20:55 mysql>
输入mysql -uroot -p , 直接按enter键, 进入到mysql里面
第5步、在mysql输入flush privileges;
root@(none) 20:58 mysql>flush privileges;
Query OK, 0 rows affected (0.00 sec)
第6步、重新设置密码
root@(none) 21:02 mysql>alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
第7步、退出mysql
vim /etc/my.cnf 将刚刚加入配置文件的skip-grant-tables 注释掉
第8步、重新刷新mysql服务
[root@nginx-kafka03 ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@nginx-kafka03 ~]#
这是用新修改的密码,登录mysql就行了。