MySQL8.0密码找回与权限刷新

开发日志:

        想必大多数开发人员都有外包经验,遇到比较悲催的情况就是,出差忘记带公司电脑,幸幸苦苦,好不容易出差回来,结果发现把公司电脑MySQL密码忘记了。直接破防!!!为了生活,只好老老实实的百度寻找答案,在这期间难免踩坑甚至要重装MySQL。在这小编整理了一份关MySQL密码找回与权限刷新的教程。


MySQL之密码重置

坑点1

大多数网上教程一般都说修改MySQL的bin目录下的my.ini 文件。然后再my.ini文件最后一行追加下面这行代码。 

skip-grant-tables

意思就是:跳过设置权限认证。我这边测试没啥用

坑点2

在MySQL的bin目录下通过管理员权限打开命令终端窗口,使用 

mysqld --skip-grant-tables 

命令,但是发现根本不适用于mysql8.0的版本,后来成功登进去了。使用如下命令又迟迟修改不了密码, 原地爆炸。

update user set password=password(‘123') where user='root' ;

对我根本没用,原因就是MySQL8.0以上不支持mysqld --skip-grant-tables 这个命令了。下面我总结一下完整流程,避免大家继续踩坑。


 步 骤 

1. 首先在任务管理器下面先把MySQL服务关闭。确保已经关闭了Mysql服务,不确定的可以通过WIN+R命令打开命令终端然后输入 net stop mysql 命令再确认一下。

net stop mysql

注意:如果出现不是内部命令或外部命令,则通过管理员权限打开命令终端再测试。如果都不行则检查你的MySQL环境变量是否配置正确。 

2. 进入mysql安装的根目录(找不到的只好搜索咯),也就是bin文件夹,我的如图:

复制其路径:D:\internetApp\mysql-8.0.25-winx64\bin。

3 通过管理员权限打开MySQL的bin目录下的命令终端窗口。可能有些小伙伴不在管理权下也能成功。这就不用多说了吧不会的可以百度,如图:

Microsoft Windows [版本 10.0.18363.535]
(c) 2019 Microsoft Corporation。保留所有权利。

C:\Windows\system32>cd /d D:

D:\>cd D:\internetApp\mysql-8.0.25-winx64\bin

D:\internetApp\mysql-8.0.25-winx64\bin>

4. 输入下面的命令,回车,它可以使你待会跳过密码验证,直接进入mysql。

mysqld --console --skip-grant-tables --shared-memory

出现下面的这些语句就说明执行成功了。 

Microsoft Windows [版本 10.0.18363.535]
(c) 2019 Microsoft Corporation。保留所有权利。

C:\Windows\system32>cd /d D:

D:\>cd D:\internetApp\mysql-8.0.25-winx64\bin

D:\internetApp\mysql-8.0.25-winx64\bin>mysqld --console --skip-grant-tables --shared-memory
2021-08-05T08:42:57.682884Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2021-08-05T08:42:57.683250Z 0 [System] [MY-010116] [Server] D:\internetApp\mysql-8.0.25-winx64\bin\mysqld.exe (mysqld 8.0.25) starting as process 17360
2021-08-05T08:42:57.686283Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-08-05T08:42:59.328042Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-08-05T08:42:59.336618Z 1 [ERROR] [MY-012271] [InnoDB] The innodb_system data file 'ibdata1' must be writable
2021-08-05T08:42:59.343927Z 1 [ERROR] [MY-012278] [InnoDB] The innodb_system data file 'ibdata1' must be writable
2021-08-05T08:42:59.352374Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2021-08-05T08:42:59.355785Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2021-08-05T08:42:59.359829Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-08-05T08:42:59.362884Z 0 [System] [MY-010910] [Server] D:\internetApp\mysql-8.0.25-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.25)  MySQL Community Server - GPL.

D:\internetApp\mysql-8.0.25-winx64\bin>

5. 再通过WIN+R命令打开一个新的命令终端窗口,输入咱以前登录mysql的命令:

mysql -u root -p

然后会出现Enter password。

6. 此时不用输入密码,直接回车,就进去了,就是这么任性。如图:

Microsoft Windows [版本 10.0.18363.535]
(c) 2019 Microsoft Corporation。保留所有权利。

C:\Windows\system32>mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

C:\Windows\system32>mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.25 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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>

 7. 输入flush privileges;命令,此命令用来刷新权限。可以理解为恢复出厂设置。注意有分号!出现Query OK就说明执行成功了。

flush privileges;

8. 使用下面的语句重置密码,出现Query OK就说明执行成功了。

ALTER USER root@localhost IDENTIFIED BY 'new_password';

9. 现在我们关闭已经打开的两个命令终端窗口,打开一个新的命令终端窗口,注意此时需要用管理员权限哦,别忘记了启动我们的MySQL服务。用新密码登录一下试试。

Microsoft Windows [版本 10.0.18363.535]
(c) 2019 Microsoft Corporation。保留所有权利。

C:\Windows\system32>mysql -u root -p
Enter password: *****
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)

C:\Windows\system32>mysql -u root -p
Enter password: *****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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>

此时我们已经成功登录 ,觉得有用的点个赞吧!!!❤

——————————————————————————————————————————

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值