当前位置: 代码网 > it编程>数据库>Mysql > Windows系统下MySQL忘记root密码的2种解决办法

Windows系统下MySQL忘记root密码的2种解决办法

2024年11月12日 Mysql 我要评论
方法1:对于忘记mysql root用户密码,常规的解决方法是启动的时候加 skip-grant-tables 选项,在绕过密码认证之后,进入mysql数据库系统,以便进行修复或重置密码等操作。在wi

方法1:

对于忘记mysql root用户密码,常规的解决方法是启动的时候加 skip-grant-tables 选项,在绕过密码认证之后,进入mysql数据库系统,以便进行修复或重置密码等操作。

在window下,怎么操作呢,接下来为您介绍。

1、window下关闭mysql相关服务

打开cmd窗口,我这里mysql服务名称设置为了mysql8031,所以这里是 net stop mysql8031

2、重新启动mysql

用下面的命令启动mysql服务

c:\users\administrator>cd /d d:\mysql8031\bin

d:\mysql8031\bin>mysqld --console --skip-grant-tables --shared-memory

通过mysqld --console --skip-grant-tables --shared-memory 启动可以跳过密码验证

3、打开另外一个cmd窗口登录mysql

c:\users\administrator>cd /d d:\mysql8031\bin

d:\mysql8031\bin>mysql -uroot
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 7
server version: 8.0.31 mysql community server - gpl

copyright (c) 2000, 2022, oracle and/or its affiliates.

oracle is a registered trademark of oracle corporation and/or its
affiliates. other names may be trademarks of their respective
owners.

type 'help;' or '\h' for help. type '\c' to clear the current input statement.

mysql>

4、设置新的root密码

update mysql.user set authentication_string='' where user='root';
flush privileges;
alter user 'root'@'localhost' identified by 'root';

5、关闭上述终端,重新启动mysql

net start mysql8031

这样就可以用修改后的密码登录进去了

c:\users\administrator>cd /d d:\mysql8031\bin\

d:\mysql8031\bin>mysql -uroot -proot
mysql: [warning] using a password on the command line interface can be insecure.
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 8
server version: 8.0.31 mysql community server - gpl

copyright (c) 2000, 2022, oracle and/or its affiliates.

oracle is a registered trademark of oracle corporation and/or its
affiliates. other names may be trademarks of their respective
owners.

type 'help;' or '\h' for help. type '\c' to clear the current input statement.

mysql>

方法2:

接下来,介绍另外一种更简单的方式。

新建一个newpass.txt文件(可以将它放在my.ini同目录)文件内容为:

alter user root@'localhost' identified by 'root';

关闭mysql服务:

net stop mysql8031

用下面的命令启动mysql服务:

d:\mysql8031\bin\mysqld.exe --defaults-file=“d:\mysql8031\my.ini” --init-file=“d:\mysql8031\newpass.txt”

具体的my.ini文件和newpass.txt文件要改成实际的位置

命令执行后界面没有变化执行下一步。

按ctrl+c终止运行,并重新启动windows服务

总结 

到此这篇关于windows系统下mysql忘记root密码的2种解决办法的文章就介绍到这了,更多相关windows mysql忘记root密码解决内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com