使用管理员权限打开命令行,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;退出 ,重新登录修改,至此密码修改成功