BluRayCD Forum

 找回密码
 立即注册【分享大片】
查看: 696|回复: 0
收起左侧

[交流分享] Windows系统下Mysql数据库忘记root密码的解决办法

[复制链接]

410

主题

177

回帖

1万

积分

Forum CEO

金币
2568 枚
体力
11800 点
kmxmxy 发表于 2011-7-20 09:32:52 | 显示全部楼层 |阅读模式
本文介绍Windows系统下Mysql root忘记密码的解决办法。

  Mysql root忘记密码的处理原则主要分两步:1、跳过权限限制,恢复root初始密码(Mysql root默认密码为空)以便进入Mysql命令行模式;2、修改重置root密码。

  我的Mysql数据库5.1的安装环境是Windows7,Mysql root忘记密码的处理主要会应用到mysqld命令工具,此工具Mysql自带,存放在Mysql安装目录的bin子目录下。

  注意事项:在使用mysqld命令处理Mysql root忘记密码问题时,必需确保Mysql服务停止,否则不会成功,如果默认已启动Mysql服务,你可以在DOS模式下输入

   
net stop mysql

停止Mysql服务。

  Mysql忘记root密码处理步骤一

  在停止了Mysql服务后,即可使用mysqld命令,在DOS模式下进入Mysql bin子目录,输入

   
C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqld --skip-grant-tables;

伴随这条命令会出现如下错误信息

   
100602 22:24:28 [Warning] '--default-character-set' is deprecated and will be removed in a future release. Please use '--character-set-server' instead.

此提示信息无关紧要,稍等片刻即告成功。

  知识点:mysqld的–skip-grant-tables参数表示在启动mysql时不启动grant-tables(授权表),主要是在忘记Mysql root管理员密码时使用。

  Mysql忘记root密码处理步骤二

  在使用完mysqld命令后,我们需要进入Mysql数据库命令行模式进行root密码更改重置操作,这里需要注意,必须另启一个CMD窗口,输入
C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -uroot

即进入Mysql数据库命令行模式

  Mysql忘记root密码处理步骤三

  使用Update等Mysql修改密码命令更改root密码,具体修改root密码命令如下:
  1. update mysql.user set password=PASSWORD('BluRayCD.com') where User='root';
复制代码
  Mysql忘记root密码处理步骤四

  ctrl+alt+delete,打开任务管理器,删除mysql,mysqld进程,然后在DOS模式下输入
   
net start mysql

启动mysql服务,之后就可以使用已修改的Mysql root密码进入Mysql管理模式了。

  至此Mysql root忘记密码后重新设置密码的操作就完成了,个人觉得Mysql root密码忘记后还是比较繁琐,在进行PHP网站开发时最好还是要做好安全准备,以防Mysql root忘记密码问题的出现。

方法2:

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server 5.1\my.ini" --console --skip-grant-tables
090515 22:06:09 [Warning] The syntax '--log' is deprecated and will be removed i
n MySQL 7.0. Please use '--general_log'/'--general_log_file' instead.
090515 22:06:09 [Warning] The syntax '--log_slow_queries' is deprecated and will
be removed in MySQL 7.0. Please use '--slow_query_log'/'--slow_query_log_file'
instead.
090515 22:06:09 [Warning] The syntax '--log' is deprecated and will be removed i
n MySQL 7.0. Please use '--general_log'/'--general_log_file' instead.
090515 22:06:09 [Warning] The syntax '--log_slow_queries' is deprecated and will
be removed in MySQL 7.0. Please use '--slow_query_log'/'--slow_query_log_file'
instead.
090515 22:06:09 [ERROR] The update log is no longer supported by MySQL in versio
n 5.0 and above. It is replaced by the binary log. Now starting MySQL with --log
-bin='' instead.
090515 22:06:09 InnoDB: Started; log sequence number 0 324221
090515 22:06:09 [Note] mysqld: ready for connections.
Version: '5.1.33-community-log' socket: '' port: 3306 MySQL Community Server
(GPL)

看到这个结果就说明MySQL已经起来了。
再开一个DOS窗口,同样切到mysql bin目录下,
C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -uroot mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.33-community-log MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

到这,你就继续按 方法一:操作就行。update完表后,退出,

然后
C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqladmin shutdown

之后正常重启MySQL服务就行了。
您知道吗,申请VIP会员可以免回复下载,无广告骚扰, 点此处申请

本版积分规则

小黑屋|手机版|Archiver|4K蓝光论坛

GMT+8, 2024-4-30 02:07

Copyright © 2001-2021, Gadaddy Cloud.

快速回复 返回顶部 返回列表