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

MySQL8 忘记密码

太尴尬了,好久没用MySQL已经忘记了用户密码,那么在Windows环境下遗忘了该怎么办呢?跟着小铃铛来看看。

解决方案

第一步:首先停止MySQL服务

PS D:\program_23\mysql-8.0.33-winx64\bin> net stop mysql
mysql 服务正在停止.
mysql 服务已成功停止。

PS:如果不先停止服务,会报错data文件夹被占用,无法修改

PS D:\program_23\mysql-8.0.33-winx64\bin> mysqld --console --skip-grant-tables --shared-memory
2025-03-05T01:29:49.096226Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2025-03-05T01:29:49.096246Z 0 [System] [MY-010116] [Server] D:\program_23\mysql-8.0.33-winx64\bin\mysqld.exe (mysqld 8.0.33) starting as process 8300
2025-03-05T01:29:49.106785Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-03-05T01:29:49.107833Z 1 [ERROR] [MY-012271] [InnoDB] The innodb_system data file 'ibdata1' must be writable
2025-03-05T01:29:49.107902Z 1 [ERROR] [MY-012278] [InnoDB] The innodb_system data file 'ibdata1' must be writable
2025-03-05T01:29:49.107947Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2025-03-05T01:29:49.108235Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2025-03-05T01:29:49.108278Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-03-05T01:29:49.108621Z 0 [System] [MY-010910] [Server] D:\program_23\mysql-8.0.33-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.33)  MySQL Community Server - GPL.

第二步:设置跳过密码

在 MySQL 8.0 版本中,--skip-grant-tables 的行为有所变化,可能导致无法直接跳过权限验证。可以尝试以下替代方法:

PS D:\program_23\mysql-8.0.33-winx64\bin> mysqld --console --skip-grant-tables --shared-memory
2025-03-05T01:31:52.968303Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2025-03-05T01:31:52.968330Z 0 [System] [MY-010116] [Server] D:\program_23\mysql-8.0.33-winx64\bin\mysqld.exe (mysqld 8.0.33) starting as process 19244
2025-03-05T01:31:52.978485Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-03-05T01:31:53.354902Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-03-05T01:31:53.709753Z 0 [Warning] [MY-011311] [Server] Plugin mysqlx reported: 'All I/O interfaces are disabled, X Protocol won't be accessible'
2025-03-05T01:31:53.825343Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2025-03-05T01:31:53.825578Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2025-03-05T01:31:53.867428Z 0 [System] [MY-010931] [Server] D:\program_23\mysql-8.0.33-winx64\bin\mysqld.exe: ready for connections. Version: '8.0.33'  socket: ''  port: 0  MySQL Community Server - GPL.

第三步:在另一个命令行界面访问MySQL

第四步:修改密码

由于当前处于--skip-grant-tables格式下,ALTER USER命令不能正常使用

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password.';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

可以使用:

SET PASSWORD FOR 'root'@'%' = 'new_password.';FLUSH PRIVILEGES;


http://www.kler.cn/a/572742.html

相关文章:

  • 【金融量化】Ptrade中交易环境支持的业务类型
  • Mysql命令大全(连接Mysql)
  • 单体架构、集群、分布式、微服务的区别!
  • Web服务器配置
  • shell文本处理
  • 美股行情数据:历史高频分钟回测数据策略分析
  • nvm的使用汇总
  • 【C++设计模式】第二篇:工厂方法模式(Factory Method)
  • mapbox高阶,结合threejs(threebox)实现立体三维飞线图
  • 15. 示例:创建AXI-Lite事务类(addr/data/rw)
  • JavaWeb-CS和BS的异同点
  • 调用链追踪(Trace ID)
  • 关于tresos Studio(EB)的MCAL配置之GPT
  • 计算机毕设-基于springboot的网上商城系统的设计与实现(附源码+lw+ppt+开题报告)
  • VSTO(C#)Excel开发起步
  • unittest框架 核心知识的系统复习及与pytest的对比
  • 厦门大学:《DeepSeek大模型赋能高校教学和科研报告》(120页PPT,建议收藏)
  • Milvus 数据批量导出实战:Python 代码解析
  • 【深度剖析】古德-图灵估计:从密码破译到NLP的统计革命
  • react精简面试题