The driver in mysql-connector-java 5 is com.mysql.jdbc.Driver,
The driver in mysql-connector-java 6 is com.mysql.cj.jdbc.Driver
1. JDBC connection Mysql5 com.mysql.jdbc.Driver:
driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false
2. JDBC connects to Mysql6 com.mysql.cj.jdbc.Driver. You need to specify the time zone serverTimezone:
driverClassName=com.mysql.cj.jdbc.Driver url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false
When setting the time zone, if you set serverTimezone=UTC, it will be 8 hours earlier than China time. , if in China,
可以选择Asia/Shanghai或者Asia/Hongkong,例如: driverClassName=com.mysql.cj.jdbc.Driver url=jdbc:mysql://localhost:3306/test?serverTimezone=Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false
Remarks:
I. If mysql-connector-java is used 6.0 or above, as follows:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>6.0.6</version> </dependency>
But your driver still uses com.mysql .jdbc.Driver, an error will be reported:
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.
At this time, you need to change com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver
II, there is another warning:
WARN: Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
It is not recommended to establish SSL connections without server authentication.
If not explicitly set, MySQL 5.5.45, 5.6.26 and 5.7.6 versions require an SSL connection by default.
To comply with applications that do not currently use SSL connections, the verifyServerCertificate attribute is set to 'false'.
If you do not need to use SSL connections, you need to explicitly disable SSL connections by setting useSSL=false.
If you need to connect using SSL, provide a trust store for server certificate verification and set useSSL=true.