Mysql忘记密码的解决办法

好久没有用数据库,难免把数据库的密码给忘了,那如果mysql 的数据库密码忘了该怎么办呢?这里介绍两种简单的方法可以重设密码!

Windows系统下如何重设密码

1.用系统管理员登陆系统。停止MySQL的服务。(可以通过“控制面板”-》“管理员工具”-》“服务”,然后在打开的窗口里找到 Mysql 服务,然后停止)
2.打开命令提示符,然后进入MySQL的安装目录,比如我的安装目录是c:\mysql, 进入C:\mysql\bin
3.跳过权限检查启动MySQL,输入下面的命令
c:\mysql\bin>mysqld --skip-grant-tables
这个时候命令提示符将会出现等待的状态。
4.重新打开一个命令提示符窗口,进入c:\mysql\bin目录,设置root的新密码mysql, 运行下面的命令:
use mysql;
update user SET password=password('new password') where user='root';
flush privileges;

5.重新启动Mysql服务,大功告成!

Unix&Linux系统下的解决办法:

1.用root或者运行mysqld的用户登录系统;
2.利用kill命令结束掉mysqld的进程。(可以打开命令行,然后运行“ps -ef | grep mysql” 来查看mysql 的进程ID, 然后利用“kill -9 mysql进程ID” 来杀掉此进程)
3.使用–skip-grant-tables参数启动MySQL Server
shell>mysqld --skip-grant-tables
4.为root@localhost设置新密码
use mysql;
update user SET password=password('new password') where user='root';
flush privileges;

5.重启MySQL Server,设置完成。

其实这两种方法就是针对不同的操作系统来进行的处理。

Mysql忘记密码的解决办法》上有 11 条评论

  1. This site appears to recieve a great deal of visitors. How do you advertise it? It gives a nice individual twist on things. I guess having something authentic or substantial to give info on is the most important factor.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>