mysql新版的jdbc驱动配置

在配置新版MySQL JDBC驱动时,出现错误提示关于服务器时区值的问题。解决方法是通过设置serverTimezone参数来指定更具体的时区。本文介绍了新版与老版驱动配置的区别,并列出了一些常用的URL参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

新版的mysqljdbc驱动jar包的配置与之前发生了改变,今天在配置mybatis中mysql驱动的时候一直报错:
org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
The error may exist in userMapper.xml
The error may involve com.ycc.mybatisStudy.userMapper.selectUser
The error occurred while executing a query
Cause: java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

自己也是检查了半天的jdbc的配置也没有发现什么问题,后来在网上百度了一下发现是jdbc的配置发生了改变

老版配置mysqljdbc驱动:

<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatisdb"/>
<property name="username" value="root"/>
<property name="password" value="root"/>

新版配置:

<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatisdb?useUnicode=true&amp;characterEncoding=utf8&amp;serverTimezone=GMT"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>

关于mysqljdbc驱动的URL参数,常用的有一些参数如下表所示:

参数名称参数说明缺省值最低版本要求
user数据库用户名 (用于连接数据库)所有版本
password用户密码(用于连接数据库)所有版本
useUnicode是否使用Unicode字符集,如果参数characterEncoding设置为gb2312或gbk,本参数值必须设置为truefalse1.1g
characterEncoding当useUnicode设置为true时,指定字符编码。比如可设置为gb2312或gbkfalse1.1g
autoReconnect当数据库连接异常中断时,是否自动重新连接?false1.1
autoReconnectForPools是否使用针对数据库连接池的重连策略false3.1.3
failOverReadOnly自动重连成功后,连接是否设置为只读?true3.0.12
maxReconnectsautoReconnect设置为true时,重试连接的次数31.1
initialTimeoutautoReconnect设置为true时,两次重连之间的时间间隔,单位:秒21.1
connectTimeout和数据库服务器建立socket连接时的超时,单位:毫秒。 0表示永不超时,适用于JDK 1.4及更高版本03.0.1
socketTimeoutsocket操作(读写)超时,单位:毫秒。 0表示永不超时03.0.1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值