mysql忘记root密码的解决方法

本文提供了一种在Windows环境下重置MySQL root密码的方法。通过停止MySQL服务并使用特定命令启动来绕过密码验证,进而更新root用户的密码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

好长时间没有用MySql了,也忘记了当时的root密码,看了好几篇文章,把自己的方法记下。

Windows下的忘记root密码的解决方法:

1、首先先检查一下MySql服务有没有打开。可以命令行里面输入 taskkill /f /im mysqld-nt.exe 先关闭MySql服务 。或者在计算机->管理>服务和应用程序里面的服务,找到mysql服务关闭。再或者也可在windows的任务管理器里面结束掉mysqld.exe 进程。


2、打开一个cmd窗口,切换到mysql的bin目录  

C:\Program Files\MySQL\MySQL Server 5.5\bin>,运行命令:

mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.5\my.ini" --console --skip-grant-tables

(这里注意,新版本的mysql的my.ini在ProgramData里面,网上的多数经验都写的在program files里

注释:

该命令通过跳过权限安全检查,开启mysql服务,这样连接mysql时,可以不用输入用户密码。

"C:\ProgramData\MySQL\MySQL Server 5.5\my.ini"指配置文件my.ini,一般在mysql安装目录里面。

如: 见图1

========================================================

C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqld --defaults-file="C:\ProgramDa
ta\MySQL\MySQL Server 5.5\my.ini" --console --skip-grant-tables
170208 16:39:51 [Note] mysqld (mysqld 5.5.46-log) starting as process 14276 ...


3、打开第二个cmd窗口,连接mysql: (这里需要说明一下可以输入命令,也可以直接 开始 - 程序 - mysql server5.5 - MySQL 5.5 Command Line Client)

输入命令:mysql -uroot -p

出现:

Enter password:

这里直接回车,不用输入密码。然后就会出现登录成功的信息,

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.46-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

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>

==============================================

使用命令切换到mysql数据库:

use mysql;

使用命令更改root密码:

UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

PS:newpassword=你将要修改的密码

刷新权限:

FLUSH PRIVILEGES;

然后退出,再次登录:

quit 

重新登录:

mysql -uroot -p

出现输入密码提示,输入新的密码即可:

如:

Enter password: ***
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.46-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

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>

=======================================================

进行到这里就算修改成功啦。

接下来把cmd窗口关闭,再次打开服务即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值