1、关闭MySQL服务
打开命令行cmd输入net stop mysql命令即可关闭MySQL服务
2、去掉认证检查
mysqld --skip-grant-tables
这个命令是去掉认证检查,这样就可以不用密码登录MySQL;为下面的操作做准备,请勿关闭!!!
3、使用管理员权限打开命令行
输入mysql回车
4、使用mysql数据库。
5、将密码清空
update user set authentication_string='' where user='root';
6、查看密码是否被清空
select host, user, authentication_string, plugin from mysql.user;
7、重新使用管理员权限打开命令行,输入net start mysql 启动mysql
8、输入命令 mysql -u root -p 登陆mysql,因为第5步清空了密码,故直接回车即可登陆;
9、修改密码为123456
alter user'root'@'%' IDENTIFIED BY '123456';
命令中的%取自于第六步图中root前面的值,有些为localhost;
10、重新查询表中字段信息。此时密码字段authentication_string不再是空,并且是密文显示
select host, user, authentication_string, plugin from mysql.user;