当前位置: 首页 > MySQL数据库

忘记mysql密码了如何重置

时间:2026-01-28 12:53:24

本教程操作环境:windows7系统、mysql8版本、Dell G3电脑。

忘记mysql密码了怎么办?不怕,可以通过重置密码了重新设置一个新密码,

重置密码的方法

1.修改配置文件 my.cnf,在配置文件 [mysqld] 下添加 skip-grant-tables,重启MySQL服务即可免密码登录

其中 --skip-grant-tables 选项的意思是启动 MySQL 服务的时候跳过权限表认证。 启动后,连接到 MySQL 的 root 将不需要口令(危险)。

[mysqld]skip-grant-tables

2.用空密码的 root 用户连接到 MySQL,并且更改 root 口令

免密码登录MySQL数据库:

[root@iZ235wguph2Z www]# mysql -u rootWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 295Server version: 5.0.56-log Source distributionCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

重置密码:

mysql> update user set password=password('123456') where User='root';ERROR 1046 (3D000): No database selectedmysql> use mysql;Database changedmysql> update user set password=password('123456') where User='root';Query OK, 3 rows affected (0.00 sec)Rows matched: 3  Changed: 3  Warnings: 0mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> exit

3.到 my.cnf 中删除 skip-grant-tables 选项,然后重启MySQL服务。


上一篇:mysql中blob和text有哪些区别
下一篇:mysql如何清除日志
mysql
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器
  • 英特尔第五代 Xeon CPU 来了:详细信息和行业反应
  • 由于云计算放缓引发扩张担忧,甲骨文股价暴跌
  • Web开发状况报告详细介绍可组合架构的优点
  • 如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳
  • 美光在数据中心需求增长后给出了强有力的预测
  • 2027服务器市场价值将接近1960亿美元
  • 生成式人工智能的下一步是什么?
  • 分享在外部存储上安装Ubuntu的5种方法技巧
  • 全球数据中心发展的关键考虑因素
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器

    英特尔第五代 Xeon CPU 来了:详细信息和行业反应

    由于云计算放缓引发扩张担忧,甲骨文股价暴跌

    Web开发状况报告详细介绍可组合架构的优点

    如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳

    美光在数据中心需求增长后给出了强有力的预测

    2027服务器市场价值将接近1960亿美元

    生成式人工智能的下一步是什么?

    分享在外部存储上安装Ubuntu的5种方法技巧

    全球数据中心发展的关键考虑因素