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

windows7下MySQL5.6忘记root密码

2014-04-18 09:06 507 查看
  以下步骤如果添加了MySQL的环境变量,则可以直接运行mysql有关命令,否则必须到mysql安装目录的bin目录下操作。

步骤如下:

1.停止mysql服务(以管理员身份,在cmd命令行下运行) net stop mysql

2.使用 mysqld –skip-grant-tables 命令启动mysql数据库

D:\>net stop mysql MySQL 服务正在停止. MySQL 服务已成功停止。

D:\>mysqld --skip-grant-tables

 



 

3.不关闭以上窗口,新开一个cmd窗口,输入mysql -u root,直接按回车键

D:\>mysql -u root

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.1.26-rc-community MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> update mysql.user set password=password('aaa') where user='root';

密码可以自己随便写。

Query OK, 1 row affected (0.02 sec) Rows matched: 2 Changed: 1 Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec) mysql>

 


 

4.打开任务管理器,停止mysql,mysqld进程,使用net start mysql启动mysqld服务,就可以使用root用户 root密码进入数据库了

mysql -u root -p aaa

补充说明:

1.mysqld使用说明可以使用如下命令获取查看:

mysqld --verbose --help > d:\mysqld_help.txt

帮助中–skip-grant-tables的帮助为:

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

所以我们可以使用mysql -uroot而不用密码直接登陆mysql,而且可以修改任何表。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息