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

解决“MySQL”忘记root密码的案例

2017-03-15 11:56 232 查看
本人电脑装有window下的MySQL,已经虚拟机下Linux下的MySQL,均忘记了root密码,故写此文!以飨读者...

注:D:\phpStudy\MySQL\bin> 为你MySQL安装的bin目录


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

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| schooldb           |
| test               |
+--------------------+
5 rows in set (0.04 sec)

mysql> use mysql
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
24 rows in set (0.00 sec)

mysql>
mysql> update mysql.user set Password=PASSWORD('guoguo') where User='root' AND Host='localhost';
Query OK, 1 row affected (0.17 sec)
Rows matched: 1  Changed: 1  Warnings: 0

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

mysql> \q
Bye

D:\phpStudy\MySQL\bin>mysql -uroot -pguoguo;
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

D:\phpStudy\MySQL\bin>mysql -uroot -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.47 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| schooldb           |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql>

D:\phpStudy\MySQL\bin>mysqld --skip-grant-tables;
170315 10:15:29 [Note] mysqld (mysqld 5.5.47) starting as process 3320 ...

D:\phpStudy\MySQL\bin>
D:\phpStudy\MySQL\bin>
D:\phpStudy\MySQL\bin>
D:\phpStudy\MySQL\bin>
D:\phpStudy\MySQL\bin>
D:\phpStudy\MySQL\bin>
D:\phpStudy\MySQL\bin>
D:\phpStudy\MySQL\bin>net start mysql --skip-grant-tables;
此命令的语法是:

NET START
[service]

D:\phpStudy\MySQL\bin>mysqld-nt --skip-grant-tables;
'mysqld-nt' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

D:\phpStudy\MySQL\bin>mysqld --skip-grant-tables
170315 10:20:38 [Note] mysqld (mysqld 5.5.47) starting as process 14744 ...


聪明的人都能看懂!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: