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

忘记 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: 0mysql> 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.lryc.cn/news/455899.html

相关文章:

  • 【LeetCode每日一题】——17.电话号码的字母组合
  • Git管理远程仓库
  • 在 /var/cache/apt/archives/ 上没有足够的可用空间的解决方法
  • FastAdmin Apache下设置伪静态
  • MPI程序实例:自适应数值积分(主从模式)
  • 蓝桥杯—STM32G431RBT6(IIC通信--EEPROM(AT24C02)存储器进行通信)
  • 【重学 MySQL】六十二、非空约束的使用
  • Python获取json返回的字符串获取方法大全
  • FreeBSD14.1 rm命令的疑惑
  • LSTM模型变种
  • 基于comsol模拟微穿孔板和卷曲通道的混合吸声器低频吸声
  • Ajax ( 是什么、URL、axios、HTTP、快速收集表单 )Day01
  • 【Java 循环控制实例详解【While do... while】】
  • 10.2 Linux_进程_进程相关函数
  • 栈与队列面试题(Java数据结构)
  • 手撕数据结构 —— 顺序表(C语言讲解)
  • 女友学习前端第二天-笔记
  • 电脑手机下载小米xiaomi redmi刷机包太慢 解决办法
  • Python中的策略模式:解锁编程的新维度
  • ara::core::Future::then()的概念和使用方法
  • 九、5 USART串口数据包
  • SQL第12课——联结表
  • CentOS7 虚拟机操作系统安装及相关配置教程
  • 『网络游戏』窗口基类【06】
  • 04_23 种设计模式之《单例模式》
  • 视频加字幕用什么软件最快?12款工具快速添加字幕!
  • C++:string (用法篇)
  • 力扣随机题
  • CSS样式基础样式选择器(案例+代码实现+效果图)
  • Linux系统编程—I/O缓冲区(C语言实现)