好长时间没有用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:/ProgramData/MySQL/MySQL Server 5.5/my.ini" --console --skip-grant-tables170208 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 4Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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 4Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.mysql>
=======================================================
进行到这里就算修改成功啦。
接下来把cmd窗口关闭,再次打开服务即可。
新闻热点
疑难解答