Mysql 忘记密码如何找回

1、先配置免密码登录
在[mysqld]下面添加skip-grant-tables

[root@localhost bin]#service mysqld stop
[root@localhost bin]# vi /etc/my.cnf 
image.png

重启数据库:
[root@ecs-03 mysql]# systemctl restart mysqld
执行命令:
systemctl stop mysqld && sed -i '/mysqld/a skip-grant-tables' /etc/my.cnf && systemctl restart mysqld
登录数据库,下面直接回车 不用输入密码:
[root@ecs-03 mysql]# mysql -u root -p
修改root数据库账号密码:
mysql> use mysql;
mysql> select host, user from user;
mysql> update user set host='%' where user='root';
mysql> flush privileges;
mysql> grant all privileges on . TO 'root'@'%' identified by 'jenkins@123' with grant option;
mysql>grant all on . to root@'localhost' identified by 'jenkins@123' with grant option;
mysql> alter user 'root'@'localhost' identified by 'jenkins@123';
mysql> flush privileges;
Mysql>exit
修改后把kip-grant-tables注释掉重启mysql

systemctl stop mysqld && sed -i 's/skip-grant-tables/#skip-grant-tables/g' /etc/my.cnf && systemctl restart mysqld

参考链接:https://www.cnblogs.com/effortsing/p/10006671.html

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容