mysql版本mysql-8.4.3-winx64
cpp
net stop mysql //关闭MySQL连接
mysqld --console --skip-grant-tables --shared-memory //跳过密码登陆MySQL控制台
此时cmd窗口卡住,继续新建cmd窗口。命令行进入MySQL的bin文件夹下,输入
cpp
mysql -hlocalhost -uroot -p
此时出现Enter password:,直接回车进入数据库
更新密码:
bash
flush privileges; //刷新MySQL系统权限相关信息表
ALTER USER root@localhost IDENTIFIED BY '新的密码'; //修改root用户密码
最后来到最开始卡住的cmd窗口,按下ctrl + C 结束命令,再执行以下语句
bash
net start mysql //开启MySQL连接