1.停止MySQL服务:net stop mysql
2.进入mysql安装目录清空data目录文件
3.输入
mysqld --skip-grant-tables
回车。--skip-grant-tables
的意思是启动MySQL服务的时候跳过权限表认证。
4.启动MySQL服务:net start mysql
5.mysql -u root -p
回车进入mysql>
#查询当前用户名密码
select host, user, authentication_string from mysql.user ;
#修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword'
#注意:authentication_string:字段表示用户密码。(老版本的mysql用的password)