1、编辑mysql配置文件my.ini(在mysql的安装目录下,我的在D:\Program Files\MySQL\MySQL Server 5.0\my.ini),在[mysqld]这个条目下添加一行 skip-grant-tables 保存退出后重启mysql;

2、cmd里面输入mysql -u root -p,登录mysql;

3、进入mysql数据库

mysql> use mysql; 
Database changed

4、给root用户设置新密码:  
mysql> update user set password=password("xxx") where user="root"; 
Query OK, 1 rows affected (0.01 sec) 
Rows matched: 1 Changed: 1 Warnings: 0

5、注释掉第1步中添加的skip-grant-tables 保存退出并重启