mysqld方式修改Mysql 5.1 root用户密码

机房电脑上的mysql总是没有说明root用户的密码,用的时候很不方便,今天实验手动改了一下了,网上有些使用了mysqld-nt方式修改也能成功参考http://www.kuqin.com/database/20080306/4249.html,不过对mysql5.1环境不适用,解决方法如下:

 

我的环境:

Windows 7 x64

Mysql 5.1.50 Community Server x32

 

先看一下mysqld命令在帮助文档中的说明吧:

--skip-grant-tables Start without grant tables. This gives all users FULL ACCESS to all tables.

skip-grant-tables                 FALSE

意思就是允许所有用户访问修改数据库中的所有表,默认是FALSE。

 

1.停止mysql服务器

D:\>net stop mysql
The MySQL service is stopping.
The MySQL service was stopped successfully.

 

2.执行mysqld --skip-grant-tables,此时的窗口会hang中。

D:\>mysqld --skip-grant-tables
120922 17:20:15 [Warning] '--default-character-set' is deprecated and will be re
moved in a future release. Please use '--character-set-server' instead.

 

3.打开另一个cmd窗口,执行mysql –uroot以无认证方式登入mysql服务器

D:\>mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.50-community MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

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

mysql>

 

4.选择mysql数据库,对mysql中的用户表user执行修改,同时刷新权限表。

mysql> use mysql
Database changed
mysql> update mysql.user set password=password('root') where user='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye

 

5.打开任务管理器,停止之前hang住的mysqld程序。

 

6.已新密码登入数据库,修改成功!

D:\>net start mysql
The MySQL service is starting.
The MySQL service was started successfully.

D:\Envirbase\mysql5.1\bin>mysql -u root -proot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.50-community MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

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

mysql>
posted @ 2012-09-22 17:58  beanbee  阅读(3363)  评论(0编辑  收藏  举报