C:\Users\Administrator>cd /d D:\SOFT_PHP_PACKAGE\mysql5.6\bin

D:\SOFT_PHP_PACKAGE\mysql5.6\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28 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> use mysql
Database changed
mysql> SHOW TABLES
    ->
    -> use mysql
    ->
    -> SHOW TABLES;
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 'use m
ysql

SHOW TABLES' at line 3
mysql> select host,user,password from mysql.user
    -> ;
+-----------+---------------+-------------------------------------------+
| host      | user          | password                                  |
+-----------+---------------+-------------------------------------------+
| localhost | root          | *A8E9DF11CF62C9617F252C39F8D99DA9526ADF97 |
| 127.0.0.1 | root          | *A8E9DF11CF62C9617F252C39F8D99DA9526ADF97 |
| %         | xxxxxxxx      | *A2F82D5DE05AFAF7DE8855199890C764C5D28681 |
| %         | xxxxxxx       | *65327D9F12D9C8B9B8CBCFCC744E5EF8430DDA0B |
| %         | xxx           | *EBEAE1FA884C705F0FE2821B9B03AE752869D6AA |
| %         | xxxxx         | *437D4FA85061C3D8877D546AED76449E3797ECD1 |
| %         | xxxxxx        | *48E6FFA7A9ADF3C2649CBE7F6C788A4B1905095E |
| %         | xxxxxxxxxxxxx | *EB89BE5409BE261FC028F552C0263690E11540BD |
| %         | xxxxxxxxxxxxx | *1D362542A682796CCEA903EC42CE7D7C6D9AE858 |
| %         | xxxxxxxxx     | *C3C51C68D56D2A2EED404970D133261CDEC83577 |
| %         | xxxxxx        | *CF31228949E6FAF7DD923FA99B0E9BA6D4FD9D3C |
| %         | xxxxxx        | *505F9C63916F2156CB5AE00BA95DC5644062D2B4 |
| %         | xxxxxx        | *4AD34F7689AFF7A2ED97FD00F171CD027A9B0639 |
| %         | xxxxxxxxxxxx  | *3C89AA0F78AB038A52CCB77C4E6374BB09B83039 |
| %         | xxxxxxxxxx    | *ED41FF5BD43DC9B4593C6AAFB5180B46D16CDBF6 |
| %         | xxxx          | *F869FE12384C5DFE0ACB00C7C6653BD112E6F557 |
| %         | xxx           | *D552A12F307FB7DA7A46E1D0BCE32A7A19B7B1CA |
| %         | xxx           | *25DA0348D56F13EB8F499CA3ADF72AEC3DD2E446 |
| %         | xxxxxxxx      | *EBA68E41FDC96C95F0ABE2FFDB7DD6CBA0BAAD5F |
+-----------+---------------+-------------------------------------------+
19 rows in set (0.04 sec)

mysql>

Windows 下如果MySQL密码忘记了root密码导致无法登录,如下图所示,

这个时候怎么办,只能重置root密码了。

1.打开任务管理器查看MySql服务是否启动,如果已启动则先将其停止

2.找到MySql目录下的my.ini文件

3.打开该文件,找到里面的[mysqld],然后在这个下面添加skip-grant-tables,添加完后保存文件

4.重新进到任务管理器将MySQL服务启动起来

5.以管理员身份运行cmd

注意这里必须以此方式用管理员身份运行cmd,不能用win+R输入cmd运行,否则会出现 “'mysql' 不是内部或外部命令,也不是可运行的程序或批处理文件”的错误。

6.输入mysql -u root -p就可以不用密码登录了,出现password:的时候直接回车可以进入。

7.进入mysql数据库:

mysql> use mysql;Database changed

8.给root用户设置新密码:mysql> update user set password=password("123456") where user="root";

提示:Query OK, 1 rows affected (0.04 sec)Rows matched: 1 Changed: 1 Warnings: 0

PS:123456为新密码,用户可根据自己需要修改成自己的密码

9.打开之前的my.ini文件将添加的"skip-grant-tables"这行删除

10.打开任务管理器重启MySQL服务。接着我们就可以用刚设置的密码 “123456”连接数据库了。

 

Mysql的root密码修改成功!

补充说明!!!

最后一步update user set password=password("root") where user="root"; 只适用于5.5版本;

5.7版本要把第一个password字段改成authentication_string;

结果为update user set authentication_string=password("123456") where user="root"

转自https://blog.csdn.net/zcczero/article/details/88683543

我登录数据库的时候是依据上面的教程,由于某些原因不敢直接修改root密码,所以先查看的,查看完了之后心凉了

我用的是mysql5.6,后期发现这时候其实可以直接建个数据库了

用navicat登root用户,建了一个数据库,然后给他建一个新用户给一个权限

mysql> CREATE USER `xxxx`@`%` IDENTIFIED BY 'xxxx888';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables opt
ion so it cannot execute this statement
又报错,执行下面这句
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
这就可以了
mysql> CREATE USER `daorun`@`%` IDENTIFIED BY 'daorun888';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT Alter, Alter Routine, Create, Create Routine, Create Temporary Tabl
es, Create View, Delete, Drop, Event, Execute, Grant Option, Index, Insert, Lock
 Tables, References, Select, Show View, Trigger, Update ON `daorun`.* TO `daorun
`@`%`;
Query OK, 0 rows affected (0.00 sec)

点赞(1) 打赏

评论列表 共有 0 条评论

暂无评论
返回
顶部