Mysql8.0重置密码(windows)

1.关闭mysql8服务(或者在windows32目录下执行:net stop mysql)

先跳过安全检查(新建命令窗口1):

进入mysql8.0的bin目录,执行以下语句:

mysqld --console --skip-grant-tables --shared-memory

报错:

2022-06-08T01:36:29.364886Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.23) starting as process 26856
2022-06-08T01:36:29.372881Z 0 [Warning] [MY-010091] [Server] Can't create test file C:\Program Files\MySQL\MySQL Server 8.0\data\mysqld_tmp_file_case_insensitive_test.lower-test
2022-06-08T01:36:29.374008Z 0 [Warning] [MY-010091] [Server] Can't create test file C:\Program Files\MySQL\MySQL Server 8.0\data\mysqld_tmp_file_case_insensitive_test.lower-test
2022-06-08T01:36:29.375508Z 0 [ERROR] [MY-013276] [Server] Failed to set datadir to 'C:\Program Files\MySQL\MySQL Server 8.0\data\' (OS errno: 2 - No such file or directory)
2022-06-08T01:36:29.402135Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-06-08T01:36:29.402240Z 0 [System] [MY-010910] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld 8.0.23) MySQL Community Server - GPL.

然后添加my.ini配置文件路径解决:

mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --console --skip-grant-tables --shared-memory

不要关闭命令窗口1,新建命令窗口2,然后输入:

myql -u root -p

不输入密码,直接回车进入mysql,然后切换数据到mysql库:use mysql;

更改密码为空(一定要为空):

update user set authentication_string='' where user='root';

然后退出(exit获取quit)

然后关闭(或者ctal+c)命令窗口1.

启动mysql8服务,然后输入mysql -u root -p回车,进入数据库修改密码:

ALTER USER 'root'@'localhost' IDENTIFIED BY '******';
FLUSH PRIVILEGES;

然后退出即可。

posted @ 2022-06-08 10:27  Shapley  阅读(499)  评论(0编辑  收藏  举报