您的位置:首页 > 数据库 > MySQL

Windows下丢失mysql root密码后的详细解决方法

2012-10-19 15:00 483 查看
前几天把root密码忘了,于是在网上转了半天,也没有找到一个完整无错的答案。于是经过几十次的尝试后,终于搞定了。也算对得起自己了。

这里把自己的详细设置方法告诉和我一样的菜鸟,希望对你们有点帮助,同时自己也做个备份。

我的mysql为MySQL - 5.0.23:

1、在开始菜单“运行”栏里输入“CMD”,http://www.lololuoluo.com,进入到了命令行下

C:\Documents and Settings\millken>

C:\Documents and Settings\millken>net stop mysql

C:\Documents and Settings\millken>mysqld-nt --skip-grant-tables

C:\Documents and Settings\millken>

2、新开一个CMD窗口:

*************************************************************************

Microsoft Windows [版本 5.2.3790]

(C) 版权所有 1985-2003 Microsoft Corp.

C:\Documents and Settings\millken>mysql -u root

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 18 to server version: 5.0.23-community-nt

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

mysql> use mysql

Database changed

mysql> update user set password=password("root") where host="localhost" and user="root";

Query OK, 0 rows affected (0.00 sec)

Rows matched: 1 Changed: 0 Warnings: 0

mysql> set password for "root"@"localhost"=old_password("root");

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables

option so it cannot execute this statement

mysql> exit;

Bye

C:\Documents and Settings\millken>d:

D:\>mysqladmin -u root shutdown

D:\>net start mysql

MySQL 服务已经启动成功。

D:\>cd www

D:\WWW>cd mysql

D:\WWW\MYSQL>cd bin

D:\WWW\MYSQL\bin>mysql -u root -p

Enter password: ****

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 35 to server version: 5.0.23-community-nt

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

mysql> set password for 'root'@'localhost'=old_password("root");

Query OK, 0 rows affected (0.00 sec)

mysql>

至此就大功告成了,注意一点的是因为5.0.1版Mysql的password算法和3.23.44的算法不一样了,所以要运行最后一句,不然phpmyadmin下会进不了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: