MySQL8.0忘记root密码解决方法

1.跳过密码进入mysql

(1)管理员权限打开cmd,先暂停mysql服务
C:\Windows\system32>net stop mysql
(2)进入mysql安装目录bin目录,运行命令mysqld --console --skip-grant-tables --shared-memory
在这里插入图片描述
(3)运行成功时,打开另外一个cmd窗口进入mysql
C:\Windows\system32>mysql -uroot -p
不需要输入密码直接Enter

2.修改密码

(1)刷新权限

mysql>flush privileges

(2)查看authentication_string是否为空,authentication_string字段用于存储加密后的密码

mysql>select user,host,authentication_string from user

(3)authentication_string字段为空的话就可以用ALTER USER修改,不能的话先将该字段设为空,否则可能会报错 ERROR 1396 (HY000): Operation ALTER USER failed for ‘root’@'localhost’

use mysql;
update user set authentication_string=’’ where user='root’

(4)修改密码,若需要支持navicat,使用mysql_native_password修改密码,毕竟8.0加密方法不一样

ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘新密码’;

不需要支持navicat:
ALTER user ‘root’@‘localhost’ IDENTIFIED BY '新密码’

修改完毕 退出第一个cmd命令,重启服务即可

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值