当前位置: 首页 > news >正文

【Mysql】忘记Root密码后如何不影响数据进行重置密码

方法一:通用方法--启动时跳过权限表

1> 停止数据库

以管理员方式打开cmd!!

C:\Users\Administrator>net stop mysql

MySQL 服务正在停止..

MySQL 服务已成功停止。

2> 启动时跳过权限表

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

C:\Users\Administrator>mysqld --console --skip-grant-tables --shared-memory

注意:不要关闭终端

3> 重开新的终端(再开一个终端),登录并设置新密码

PS C:\Users\Administrator> mysql -uroot -p

Enter password: 直接敲回车键

mysql> flush privileges;

mysql> alter user root@localhost identified by '123456'; //重置密码

4> 退出MySQL,关闭第一个终端,正常启动服务。

mysql> \q

PS C:\Users\Administrator> net start mysql

MySQL 服务正在启动 ..

MySQL 服务已经启动成功。

PS C:\Users\Administrator> mysql -uroot -p123456

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, 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> \q

Bye

方法二:参考官方文档

1> 停止服务

PS C:\Users\Administrator> net stop mysql

MySQL 服务正在停止.

MySQL 服务已成功停止。

2> 创建一个文本文件到mysql文件夹里,保存为 mysql_init.txt ,内容如下:

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

3> 启动同时使用上一步文件修改密码

要求管理员身份打开cmd来运行命令,暂时不要关闭终端:

C:\Users\Administrator>mysqld --init-file= F:\mysql\mysql-8.0.36-winx64\mysql_init.txt

(具体路径复制粘贴)

4> 打开另一个终端,登录测试

PS C:\Users\Administrator> mysql -uroot -p123456

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, 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> \q

Bye

5> 关闭第一个终端,正常启动服务。

C:\Users\Administrator>net start mysql

MySQL 服务正在启动 ..

MySQL 服务已经启动成功。

C:\Users\Administrator>mysql -uroot -p123456

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, 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> \q

Bye

6> 删除文件 mysql_init.txt

http://www.lryc.cn/news/500621.html

相关文章:

  • 宝塔内设置redis后,项目以及RedisDesktopManager客户端连接不上!
  • 一文了解模式识别顶会ICPR 2024的研究热点与最新趋势
  • 【深度学习】深刻理解BERT
  • 一种基于通义千问prompt辅助+Qwen2.5-coder-32b+Bolt.new+v0+Cursor的无代码对话网站构建方法
  • Java版-图论-最小生成树-Kruskal算法
  • 计算机网络知识总结
  • 普通算法——欧拉筛
  • 【知识科普】DNS(域名解析服务)深入解读
  • 数据结构第一弹-数据结构在不同领域的应用
  • 如何创建基于udp的客户端和服务端
  • ThinkPHP框架审计--基础
  • Java8 CompletableFuture异步编程
  • Java的Mvc整合Swagger的knife4框架
  • 分阶段构建在复杂系统中的应用:以推荐系统为例
  • 2024年12月9日历史上的今天大事件早读
  • 快捷构建AI大模型,源码自取可直接运行
  • 怎么为开源项目做贡献提PR?
  • 如何在 JavaScript 中设置定时器?
  • 【学习路线】Java
  • [GYCTF2020]Easyphp
  • JavaScript 数组的高级用法与最佳实践
  • 通信协议 http、tcp、udp
  • Scala的隐式对象和隐式类
  • 【AIGC】2016-ACCV-即时追捕:自然环境下的自动唇音同步
  • 启智畅想集装箱箱号识别算法,2台相机即可实现较高识别率
  • 让IIS支持PUT请求解决IIS里不支持PUT请求的问题405 Method Not Allowed
  • 入门级捡垃圾工作站记录
  • 2024.12.9——攻防世界ics-06
  • 微信小程序介绍-以及写项目流程(重要)
  • 国内国际标准!羊毛衫检测项目、检测要求及标准