mysql8下忘记密码后重置密码的办法
解决方法:mysql8后,mysqld.exe 提供了 --init-file参数来实现对密码的重置。
具体实现方法:
1 . 建一个txt文件,记下它的路径,并在文件里写入
将密码设为空
alter user 'root'@'localhost' identified by '';# 将密码重置为空
或者重置为新密码 :alter user ‘root’@‘localhost’ identified with mysql_native_password by ‘新密码’;
alter user 'root'@'localhost' identified with mysql_native_password by 'wo520Python'; #
如下图所示
2. 复制创建文件的路径
如上图所示,路径为: G:\mysql-8.0.15-winx64\croot.txt
3.管理员权限打开cmd
1 .关闭mysql服务器
net stop mysql
2 .执行下命令 mysqld --init-file=文件路径 --console
注意:–init-file后=与旁边字符不能留空格
mysqld --init-file=G:\mysql-8.0.15-winx64\croot.txt --console
如下图所示
4.最后,关闭mysqld.exe 进程,启动mysql服务器
1.打开另一个管理员权的cmd,输入下述命令
taskkill /im mysqld.exe -f
2.启功mysql
net start mysql
如下图所示