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

忘记 MySQL 密码怎么办:破解 root 账户密码

忘记 MySQL 密码怎么办:破解 root 账户密码

目录

  • 忘记 MySQL 密码怎么办:破解 root 账户密码
        • 1、修改 MySQL 配置文件
        • 2、不使用密码登录 MySQL
        • 3、重置 root 用户密码
        • 4、修改 MySQL 配置文件并重启 MySQL 服务
        • 5、使用新密码登录 MySQL

如果忘记密码导致无法登录 MySQL ,可以采用如下方法使 root 密码失效,然后不使用密码登录 MySQL,重新设置新密码。步骤如下:

1、修改 MySQL 配置文件

在 MySQL 配置文件的 [mysqld] 选项下加入如下代码:

[mysqld]
...
skip-grant-tables
...

然后重启 MySQL 服务:

C:\Users\Administrator>net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。


C:\Users\Administrator>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
2、不使用密码登录 MySQL
C:\Users\Administrator>mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.48 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>
3、重置 root 用户密码

方法一:修改 MySQL 数据库中的 user 表

-- 选择 mysql 数据库
mysql> use mysql
Database changed

-- 更新 user 表
mysql> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *97CFEED34A83BE1C8CA2D879A71A978A9B14568F |
| root | 127.0.0.1 |                                           |
| root | ::1       |                                           |
|      | localhost |                                           |
+------+-----------+-------------------------------------------+
4 rows in set (0.01 sec)

-- 刷新权限
mysql> update user set password=password('123456') where user='root' and host='localhost';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

方法二:使用 set password 命令

-- 格式:set password for 用户名@localhost = password(‘新密码’);
mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
4、修改 MySQL 配置文件并重启 MySQL 服务

(1)删除 MySQL 配置文件中的如下内容

[mysqld]
...
# skip-grant-tables   # 删除此行
...

(2)重启 MySQL 服务

C:\Users\Administrator>net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。


C:\Users\Administrator>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
5、使用新密码登录 MySQL
C:\Users\Administrator>mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.48 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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.

http://www.kler.cn/news/332746.html

相关文章:

  • 【JavaEE】http/https 超级详解
  • 认知杂谈97《兼听则明,偏听则暗》
  • 考研日语 - 高频核心 2200 词(八)
  • 【py】python实现矩阵的加、减、点乘、乘法
  • 多线程-初阶(1)
  • QT系统学习篇(1)
  • 算法笔记(九)——栈
  • 在springboot项目中实现一个定时任务执行的功能
  • 基于Springboot+Vue的小区停车场管理系统登录(含源码数据库)
  • wsl2 ubuntu 桥接以太网卡
  • git维护【.gitignore文件】
  • Microsoft 更新 Copilot AI,未來將能使用語音並看到你瀏覽的網頁
  • SpringCloud学习记录|day2
  • 手机实时提取SIM卡打电话的信令声音-(题外、插播一条广告)
  • Ubuntu安装Hadoop3.4
  • 书生大模型实战(从入门到进阶)L3-彩蛋岛-InternLM 1.8B 模型 Android 端侧部署实践
  • 常见的VPS或者独立服务器的控制面板推荐
  • 华为云LTS日志上报至观测云最佳实践
  • MFC有三个选项:MFC ActiveX控件、MFC应用程序、MFC DLL,如何选择?
  • Kotlin:2.0.20 的新特性