mysql忘记密码
-
跳过密码验证
使用管理员身份进入dos -> 停止mysql服务 -> 以下输入命令
net stop mysql
mysqld --console --skip-grant-tables --shared-memory
-
进入mysql系统
重新打开一个dos窗口,无密码登录
mysql -u root -p
-
清空密码,并刷新
update mysql.root set authentication_string='' where user='root' and host='localhost';
flush privileges;
-
关闭打开的两个dos窗口,重新开启一个dos窗口,就可以无密码进入mysql
mysql -u root -p
-
修改密码
alter user root@localhost identified by '新密码';
按照以上操作就可以设置新的密码
尝试过其他方式:跳过密码验证,然后直接执行命令update mysql.root set authentication_string=PASSWORD('新密码') where user='root' and host='localhost'
修改新密码。
这一种方式虽然mysql.root表中密码已经修改了,但是还是无法登录验证成功
本篇参照其他大佬的博客 https://www.cnblogs.com/wangjiming/p/10363357.html