From fffc0949cea4b7b34d7188569ef9815e2b5a0b2f Mon Sep 17 00:00:00 2001 From: wenyongda Date: Mon, 10 Feb 2025 14:32:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/_posts/MySQL.md | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/source/_posts/MySQL.md b/source/_posts/MySQL.md index 934378f..28ee339 100644 --- a/source/_posts/MySQL.md +++ b/source/_posts/MySQL.md @@ -527,7 +527,57 @@ alter user 'root'@'localhost' IDENTIFIED BY '123456'; grant all privileges on *.* to root@'%' identified by "123456"; ``` +## 忘记密码重置 +### Windows + +1. 首先停止服务 + 使用管理员用户打开CMD + + ```cmd + net stop MYSQL + ``` + + > MYSQL为MySQL数据库服务名称 + +2. 将MySQL 数据目录 C:\ProgramData\MySQL\MySQL Server 5.7 下的Data目录复制到 程序目录 C:\Program Files\MySQL\MySQL Server 5.7 下 + +3. 进入MySQL bin目录 + + ```cmd + cd "C:\Program Files\MySQL\MySQL Server 5.7\bin" + mysqld --skip-grant-tables + ``` + + > --skip-grant-tables 的意思是启动 MySQL 服务的时候跳过权限表认证 + +4. 重新打开一个cmd窗口,输入 mysql 回车 + ```cmd + cd "C:\Program Files\MySQL\MySQL Server 5.7\bin" + mysql + ``` + +5. 连接权限数据库:use mysql + +6. 修改数据库连接密码 + ```cmd + update user set authentication_string =password('123456') where user='root'; + flush privileges; + exit; + ``` + +7. 修改root 密码后,需要执行下面的语句和新修改的密码。不然开启 mysql 时会出错 + ```cmd + mysqladmin -u root -p shutdown + ``` + +8. 将程序目录 C:\Program Files\MySQL\MySQL Server 5.7 下的Data文件夹下复制到数据目录 C:\ProgramData\MySQL\MySQL Server 5.7 下 + +9. 重启 mysql + + ```cmd + net start mysql + ``` # 存储过程和函数