本地mysql数据库忘记密码修改

105 阅读1分钟

数据库mysql版本:8.4.2

1. 管理员模式打开cmd,关闭mysql服务

net stop mysql

2. 管理员模式打开cmd,进入到mysql的bin目录

输入mysql --console --skip-grant-tables --shared-memory 跳过密码输入授权

3. 再重新打开一个管理员模式的cmd窗口

执行命令

mysql
use mysql
alter user'root'@'localhost' identified with mysql_native_password by '123456' ;

image.png

image.png

执行第三句修改命令时候如果出现“ The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement"则刷新一下。

image.png

flush privileges;
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';