过程为:
1、以管理员权限打开cmd命令行,停止MySQL服务 net stop mysql80(我的MySQL服务名就多个80)
(在尝试中,网上的my.ini在我的安装目录下没找到,结果在ProgramData下找到了,我就复制了一份到我安装目录下)
2、mysqld --console --skip-grant-tables --shared-memory (必须关服务)
3、另打开个cmd窗口,输入mysql(找不到命令就配环境变量或切换到安装目录bin),无密登录
4、FLUSH PRIVILEGES; //刷新MySQL的系统权限相关表,否则会出现拒绝访问
(因为之前,直接update这个字段authentication_string(我傻傻得以为改密码成功了),后知道mysql必须要什么加密得41位,然后要alter是不成功得,心想真不该随便得尝试解决问题,要认清再解决,后找到解决方法:UPDATE user SET authentication_string='' WHERE user='root' and host='localhost';更新为空再alter就成功了!)
5、user mysql;ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; 关闭窗口就行了!记得重启MySQL服务
6、改完密码还报错,可能mysql client太低了(新Mysql坑真多,后悔)Client does not support authentication protocol requested by server; consider upgrading MySQL client
7、解决方法:cmd -> mysql -uroot -p 改好得密码;use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
8、接着报错,Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property,查找原因,之前连接得url为 "jdbc:mysql://localhost:3306/orderuser",在后边添加编码格式就好了, "jdbc:mysql://localhost:3306/orderuserjdbc:mysql://localhost:3306/orderuseruseUnicode=true&characterEncoding=UTF-8"
9、还报错(呵呵):XML Parser Error on line 14: 对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾。正常连接不用xml是没有这个错得,结果办法就是url改为"jdbc:mysql://localhost/orderuser?useUnicode=true&characterEncoding=UTF-8" '&'符号不能单独变为& 原因我也不想找了,因为已经身心疲惫,一个下午已经过去了,写完已经晚上了。
参考:该博客链接https://blog.youkuaiyun.com/baidu_32363401/article/details/81544573
还有这个(感觉很厉害):https://www.cnblogs.com/jjg0519/p/9034713.html
官网给得办法可以看这个链接:https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
因为网上我搜得方法是 B.6.3.2.3 Resetting the Root Password: Generic Instructions 没用第一种(可能没试通)
B.6.3.2.1 Resetting the Root Password: Windows Systems