网上好多旧版本修改方式,8版本以上各种报错,本人也是在各种试错以后,总结的完整争取的方式:
1、net stop mysql 停止mysql服务
2、mysqld --console --skip-grant-tables --shared-memory (旧版本命令:mysql -nt --skip-grant-tables 不可用),执行成功有日志打印,掠过权限校验,方便后续清空密码
3、新开一个窗口,mysql bin目录下,mysql -uroot -p 不用输密码直接enter登录。
4、show databases(可省略,只是为了只管查看数据库mysql),use mysql (选中mysql库) select table_name from information_schema.tables where table_schema='mysql';(可省略,查看mysql库的表), select host,user,authentication_string from user;(查看user 表关键字段),清空密码update user set authentication_string='' where user='root'; 方便下次正常(非略过--skip-grant-tables权限下)无密码登录。
5、exit 推出
6、mysql -uroot -p 不用输密码直接enter登录。
7、ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
8、如果用户记得密码能正常登录,需要修改密码,直接跳到第7步,FLUSH PRIVILEGES; 刷新权限,exit,重新登录。