Mysql root密码忘记找回妙招

109 篇文章 153 订阅

微信公众号:IT邦德
在这里插入图片描述
目前B站正在直播Mysql、Oracle实战
详情关注公众号:IT邦德 QQ群:955286955、168797397

一、Mysql root用户密码忘记(8.0以下)
1.用命令编辑/etc/my.cnf配置文件
即:vim /etc/my.cnf 或者 vi /etc/my.cnf
2.在[mysqld]下添加skip-grant-tables,然后保存并退出
3.重启mysql服务:service mysqld restart
4.更改root用户名
重启以后,执行mysql命令进入mysql命令行

5.修改root用户密码

update mysql.user set authentication_string=password('root') where user='root';   --5.7版本
flush privileges;

6.把/etc/my.cnf中的skip-grant-tables注释掉,然后重启mysql
即:service mysqld restart
好了,下面就可以用root新的密码登录了!

二、Mysql root用户密码忘记(8.0及以上)**
在mysql8系统下,适用如下方法(全路径)

G:\mysql-8.0.23-winx64\bin\mysqld --datadir=G:\mysql-8.0.23-winx64\data80323308 --console --skip-grant-tables --shared-memory

在这里插入图片描述
然后再开一个窗口,执行下面命令
cd G:\mysql-8.0.23-winx64\bin
在这里插入图片描述

mysql> select user,host,authentication_string from mysql.user;
mysql> delete from mysql.user where user='root' ;
mysql> flush privileges;   --记得刷新哈,如果提示无法创建
mysql> create user root@'%' identified with mysql_native_password by 'root';
mysql> grant all on *.* to root@'%' with grant option;
mysql> flush privileges;
mysql> drop user 'root'@'localhost';
mysql> flush privileges;
mysql> create user root@'localhost' identified with mysql_native_password by 'root';
mysql> grant all on *.* to root@'localhost' with grant option;
mysql> flush privileges;

在这里插入图片描述
好了,下面就可以用root新的密码登录了!

  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT邦德

客户部署资料,步骤超详细

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值