mysql忘记密码重置方法(mysql8)

本文提供了一种在Windows环境下重置MySQL 8.0.15版本密码的详细步骤,包括删除data文件夹、使用管理员权限运行命令、初始化数据库并获取临时密码、修改密码等关键操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、删除根目录下整个data文件夹(方便重新获取密码)

2、管理员权限打开cmd(必须以管理员权限!)
进入根目录
C:\Windows\system32>d:
D:>cd D:\mysql\mysql-8.0.15-winx64\bin

3、执行 net stop mysql 关闭mysql服务

4、根路径下bin下执行如下操作(mysqld --initialize --console)

	D:\mysql\mysql-8.0.15-winx64\bin>mysqld --initialize --console

5、等待第四步生成密码,记下密码

	这个是初始密码,复制出去待会儿要用	root@localhost: g8D+U=Idg(Gg(位置在下边代码cmd页面的倒数第二行结尾)
	得到密码  g8D+U=Idg(Gg
	
	2019-03-14T06:51:36.043507Z 0 [System] [MY-013169] [Server] D:\mysql\mysql-8.0.15-winx64\bin\mysqld.exe (mysqld 8.0.15) initializing of server in progress as process 9068

2019-03-14T06:51:36.043786Z 0 [ERROR] [MY-010338] [Server] Can’t find error-message file ‘D:\mysql-8.0.15-winx6in\share\errmsg.sys’. Check error-message file location and ‘lc-messages-dir’ configuration directive.
2019-03-14T06:51:36.044362Z 0 [Warning] [MY-013242] [Server] --character-set-server: ‘utf8’ is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2019-03-14T06:51:40.987103Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: g8D+U=Idg(Gg
2019-03-14T06:51:42.527624Z 0 [System] [MY-013170] [Server] D:\mysql\mysql-8.0.15-winx64\bin\mysqld.exe (mysqld 8.0.15) initializing of server has completed

6、开启mysql服务 net start mysql

7、输入 mysql -u root -p
Enter password:(将刚刚初始密码放这) 密码----> g8D+U=Idg(Gg

8、更改密码

mysql> alter user ‘root’@‘localhost’ identified with mysql_native_password by ‘admin’;

	这里的 引号 复制过去如果是中文( 'root'@'localhost'   'admin' ),记得改成英文,同时 'root'@'localhost' 中的@复制过去有空隙的要让它们挨在一起,不然会报错,

Query OK, 0 rows affected (0.01 sec)
此时就成功了,用户为root 密码为admin

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

mysql> quit;
Bye

8、更改成功后,重输入自己的密码测试
D:\mysql\mysql-8.0.15-winx64\bin>mysql -u root -p
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.15 MySQL Community Server - GPL

Copyright © 2000, 2019, 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> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
±-------------------+
4 rows in set (0.01 sec)

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值