首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >mysql驱动参数变化

mysql驱动参数变化

作者头像
编程随笔
发布于 2019-09-11 16:01:08
发布于 2019-09-11 16:01:08
3.1K0
举报
文章被收录于专栏:后端开发随笔后端开发随笔

在java平台使用的mysql jdbc驱动为:mysql-connector-java。 在项目中添加如下依赖:

代码语言:javascript
复制
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>${version.mysql.connector}</version>
</dependency>

在6.0.2版本之前

代码语言:javascript
复制
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://host:port/dbname?characterEncoding=utf8

在6.0.2版本之后

代码语言:javascript
复制
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://host:port/dbname?characterEncoding=utf8&serverTimezone=UTC

mysql-connector-java参数变化

1.从6.0.2版本开始,驱动类不再是com.mysql.jdbc.Driver,需要配置为:com.mysql.cj.jdbc.Driver。 否则,在启动时会提示警告日志:

代码语言:javascript
复制
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

2.从6.0.2版本开始,如果mysql server未明确配置时区,则必须在jdbc连接参数中设置serverTimezone。 否则,在启动时报错:

代码语言:javascript
复制
Exception in thread "main" 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.
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-10-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • 在6.0.2版本之前
  • 在6.0.2版本之后
  • mysql-connector-java参数变化
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档