mysq8.0及 以上 密码忘记修改方法

使用管理员权限打开命令行,net stop mysql 停止mysql 服务

执行mysqld --console --skip-grant-tables --shared-memory 在启动mysql服务的时候跳过权限验证,不使用密码直接登录

在这里插入图片描述

执行完毕之后当前命令行被占用,重新使用管理员权限打开一个新的命令行

进入到mysql的bin目录 ,执行mysql,继续执行use mysql;

update user set authentication_string = ‘’ where user=‘root’ ; 将root用户的密码清空;

在这里插入图片描述
在这里插入图片描述执行ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘新密码’; 修改密码
这里可能会报错
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
执行一下 flush privileges;退出 ,重新登录修改,至此密码修改成功
在这里插入图片描述在这里插入图片描述
在这里插入图片描述

然后重启mysql服务,输入密码登录mysql

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_38384994/article/details/105861067