Home > Database > Mysql Tutorial > body text

Let's talk about how mysql-connector-java connects to the driver

藏色散人
Release: 2021-11-24 16:30:56
forward
2473 people have browsed it

This article will introduce you to the mysql-connector-java connection driver problem. I hope it will be helpful to you!

mysql-connector-java connection driver problem

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
Copy after login

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
Copy after login

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
Copy after login

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>
Copy after login

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.
Copy after login

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.
Copy after login

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.

Recommended study: "mysql video tutorial"

The above is the detailed content of Let's talk about how mysql-connector-java connects to the driver. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!