在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
。
否则,在启动时会提示警告日志:
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
。
否则,在启动时报错:
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.