1.打开cmd
停止mysql服务
net stop mysql
# 或
打开服务找到mysql服务手动关闭
2.进入跳过授权表
模式
mysqld --console --skip-grant-tables --shared-memory
3.另开cmd窗口,输入mysql
进入mysql服务
mysql
4.输入use mysql
进入mysql数据库,再将authentication_string
改为空
use mysql;
update user set authentication_string="" where user="root";
5.刷新权限并退出
flush privileges;
exit;
6.回到第一个cmd
使用ctrl+c
退出“跳过授权表”模式,启动mysql服务
mysql -uroot -p
7.使用空密码进行登录,然后使用alter
语句更新密码,刷新权限,退出
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
flush privileges;
exit
8.重新登录
mysql -uroot -p
123456