本文共 1500 字,大约阅读时间需要 5 分钟。
今天突然手抖了一下,不小心把navicat中mysql的连接删掉了,当我想再次连接到mysql时才发现密码不记得了。马上百度了一下,发现还是有解决办法的,悬着的心这才放下来。
1.编辑 /etc/my.cnf 文件,在 [mysqld]配置中增加一句 skip-grant-tables
vim /etc/my.cnfsymbolic-links=0log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid# 新增skip-grant-tables
2.重启mysql
systemctl restart mysqld
3.登陆mysql,不用输入用户名,密码,直接回车就可以。
[root@localhost ~]# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
4.重置root密码
mysql> flush privileges;mysql> alter user 'root'@'localhost' identified by 'your 新密码' ;
5.退出mysql命令行,编辑 /etc/my.cnf 删除 skip-grant-tables,再次重启mysql
# 删除这条配置skip-grant-tablessystemctl restart mysqld
6.使用新密码登陆mysql
[root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
转载地址:http://secmb.baihongyu.com/