mysql 8.0 采坑总结

一、安装采坑

mysql 8.0安装成功后使用 navicat 打开连接,会报 2059 错误
(1)报错提示:2059 - Authentication plugin ‘caching_sha2_password’ cannot be loaded:����
在这里插入图片描述

(2)错误原因:安装时选择了强加密规则 caching_sha2_password,与之前 mysql 版本 mysql_native_password 规则不同,vavicat 驱动目前不支持新的加密规则

(3)解决方法:
1.cmd 输入命令:mysql -u root -p

2.分别执行命令:use mysql;
select user,plugin from user where user=’root’;
可以看到当前用户的加密方式为 caching_sha2_password

3.分别执行命令:ALTER USER ‘test’@’%’ IDENTIFIED BY ‘123456’ PASSWORD EXPIRE NEVER; #修改加密规则
ALTER USER ‘test’@’%’ IDENTIFIED WITH mysql_native_password BY ‘123456’;#修改密码
FLUSH PRIVILEGES;#刷新

4.正常链接数据库

二、使用 mybatis 连接 mysql,抛出异常

(1)异常信息:Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver’. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

(2)错误原因:数据库连接驱动的方式不适用,mysql 8.0 以后使用了新的连接方式。

(3)解决方法:使用最新的mysql连接驱动,即将 ‘com.mysql.jdbc.Driver’ 改为 ‘com.mysql.cj.jdbc.Driver’

三、使用 mybatis 查询数据时候发生异常

(1)异常信息:java.sql.SQLException: Zero date value prohibited

(2)错误原因:主要是由于 zeroDateTimeBehavior 的最终有效值的设置问题,zeroDateTimeBehavior 的值有三个,官方手册中,三个参数的详细解释如下:

exception (the default), which throws an SQLException with an SQLState of S1009.
convertToNull, which returns NULL instead of the date.
round, which rounds the date to the nearest closest value which is 0001-01-01.
http://dev.mysql.com/doc/connector-j/5.1/en/connector-j-installing-upgrading-3-0-to-3-1.html

默认情况为 exception,设置这个属性会抛出一个 SQLException 异常,其 SQLSate 码为 S1009。这个状态码在写存储过程处理异常时也可以用到。
convertToNull,返回 null 来替代 0000-00-00 这样的日期。
round,将日期转换为 0001-01-01。

(3)解决方法:通过给 jdbc 链接增加 zeroDateTimeBehavior 参数来解决。如果你的错误信息中有 java.sql.SQLException: Value ‘0000-00-00’ can not be represented as java.sql.Date 这个异常,那么出现 0000-00-00 属于一个无效日期,用convertToNull 属性即可。否则可使用 round,这里我给出一个添加的参考方式

jdbc:mysql://localhost:3306/seckill?characterEncoding=utf-8&useSSL=false&zeroDateTimeBehavior=round

四、关于时区问题

(1)异常:mysql 连接时还有可能会报一个时区的问题,如果你的 mysql 未设置时区,可能会报 Time_Zone 的错误

(2)解决方式:可以通过添加 serverTimezone 来解决

jdbc:mysql://localhost:3306/seckill?characterEncoding=utf-8&useSSL=false&zeroDateTimeBehavior=round&serverTimezone=UTC

以上应该就是 mysql 8.0 以上连接的最常见的问题了,还有一个,如果你是 maven 集成的项目,记得要在 pom.xml 中将 mysql 的驱动版本改为你安装的相对应的 mysql 版本,理论上应该 8.0 以上的版本都是可以的

如果还有新的坑,欢迎留言讨论!

参考链接:
https://blog.csdn.net/a745233700/article/details/80419136
https://blog.csdn.net/kwy15732621629/article/details/80065779
https://blog.csdn.net/qq_38345606/article/details/82287065
https://blog.csdn.net/qq_42909551/article/details/81710302
https://blog.csdn.net/sunforraining/article/details/80055435

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值