mysql 8.0数据库忘记root密码

最底部有遇到的问题及解决方案,欢迎补充

Windows系统mysql 8.0忘记root密码,修改步骤

第一步: 使用管理员权限打开命令提示符,在命令行输入 net stop mysql,或者直接打开服务,停止mysql服务

第二步: 服务停止后,在命令行中输入mysqld --console --skip-grant-tables --shared-memory,此时该窗口被锁定

image.png

第三步: 打开一个新的命令提示符窗口,输入mysql -uroot -p回车,提示输入密码,直接点回车进入

第四步: 输入 use mysql;

第五步: 输入 update user set authentication_string='' where user='root';,将authentication_string置空,不清空可能引起修改失败,可以尝试不清(未验证过)。

注:在mysql8.0以上版本, update mysql.user set password='newpassword' where user='root'; update mysql.user set password=PASSWORD('newpassword') where User='root';这两条命令已经不起作用了。

第六步: 输入 alter user 'root'@'localhost' identified by 'newpassword'; newpassword是要设的新密码。

第七步: 如果提示设置成功,则输入: flush privileges;(必须刷新) 。完成后Ctrl+Z退出mysql,使用新密码重新登录即可。

第八步: 如果提示不成功,则关闭两个命令提示符,重新打开一个管理员权限的命令提示符窗口,输入: mysql -uroot -p 后回车,输入密码时直接按回车进入(因为此时密码已被置空)。

第九步: 重复步骤4,步骤6,步骤7

 

linux MySQL密码重置

步骤参考Windows第三步开始

 

坑 坑

第一个坑: MySQL关于ERROR 1290 (HY000)报错

解决方案:刷新MySQL权限相关表即可解决-:flush privileges

image.png

 

第二个坑: mysql -uroot -p 登陆mysql提示Character set ‘utf-8’ is not a compiled character set and is not specified

解决方案:
在mysql安装目录下找到my.ini(默认路径D:/Program Files(x86)/MySQL/MySQL Server 8.0), 找到default-character-set将值改成utf8,重新打开命令提示符再次登录即可成功

image.png

posted on   五官一体即忢  阅读(1022)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示