Windows:
1.用系统管理员登陆系统。
2.停止MySQL的服务。
3.进入命令窗口,然后进入MySQL的安装目录,比如我的安装目录是c:mysql,进入C:mysql\bin
4.跳过权限检查启动MySQL,
c:mysql\bin>mysqld-nt --skip-grant-tables
5.重新打开一个窗口,进入c:mysqlbin目录,设置root的新密码
c:mysql\bin>mysqladmin -u root flush-privileges password "newpassword"
c:mysql\bin>mysqladmin -u root -p shutdown
将newpassword替换为你要用的root的密码,第二个命令会提示你输入新密码,重复第一个命令输入的密码。
6.停止MySQL Server,用正常模式启动Mysql
7.你可以用新的密码链接到Mysql了。
按照说明一步一步来可以执行,但是最后新的密码不管用,重启MYSQL,不行.重启服务器,还是不行!所以请教了很多人,学到了下面的重设密码的办法!
用安全模式启动之后按照文章内的步骤修改,
C:\mysql\bin>mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.0.15-nt
Type ''help;'' or ''\h'' for help. Type ''\c'' to clear the buffer.
mysql> update user set password=password(''root'') where user=''root'';
ERROR 1046: No Database Selected
mysql> use mysql
Database changed
mysql> select host,user from user;
+-----------+------+
| host | user |
+-----------+------+
| % | |
| % | root |
| localhost | |
| localhost | root |
+-----------+------+
4 rows in set (0.02 sec)
mysql> update 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.02 sec)
mysql> quit
Bye
C:\mysql\bin>mysql -uroot
ERROR 1045: Access denied for user: ''root@localhost'' (Using password: NO)
C:\mysql\bin>mysql -uroot -proot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6 to server version: 4.0.15-nt
Type ''help;'' or ''\h'' for help. Type ''\c'' to clear the buffer.
mysql> quit
Bye
C:\mysql\bin>
原来root没有密码,后来改成为root了,注意:我直接修改了两个root的密码,可以根据host不同分别修改,忘记密码也可以用这个办法重设!