MySQL connector Java driver version problem

Time:2021-8-10

MySQL connector Java driver version problem

Because my database version is 5.7.28, there are often version problems when using java to connect to MySQL.

  • com.mysql.jdbc.DriverIt is in MySQL connector Java 5,

  • com.mysql.cj.jdbc.DriverIt is in MySQL connector Java 6

It is not recommended to use server authentication to establish an SSL connection.
If not explicitly set, MySQL versions 5.5.45 +, 5.6.26 + and 5.7.6 + require SSL connection by default.
In order to comply with applications that do not currently use SSL connections, the verifyservercertificate property is set to ‘false’.
If you do not need to use SSL connection, you need to explicitly disable SSL connection by setting usessl = false.
If you need to connect with SSL, provide a truststore for server certificate verification and set usessl = true.

SSL – Secure Sockets Layer

  • 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.
Error reporting reason:
    The driver URL used for MySQL 5 is com.mysql.jdbc.driver. After MySQL 6, it is com.mysql.cj.jdbc.driver. If the version does not match, the driver class will be reported as outdated.
resolvent:
    Changing the driver class name in the configuration file can eliminate the warning of driver class obsolescence.

Even if the driver name of MySQL 5.7.28 is changed to com.mysql.cj.jdbc.driver, an error will still be reported because the version in the POM project object model file is not changed to

MySQL connector java8.0 or above

Corresponding versions of MySQL connector Java and MySQL

mysql-connector-java与Mysql对应版本

  • Because my mysql5.7.28 uses connector java version 5.1, the above error will still appear. Therefore, use connector Java above mysql5.6 and 8.0,

    Moreover, the time zone needs to be set when using

    driverClassName=com.mysql.cj.jdbc.Driver
    url=jdbc: mysql://localhost:3306/ Database name? serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false
    username=root
    password=
    • The servertimezone here must be written servertimezone = Asia / Shanghai, and an error will be reported if it is written servertimezone = Shanghai. It seems that we can’t find the time zone of Shanghai. There may be more than one Shanghai in the world, ha ha!

Corresponding versions of MySQL connector Java and Java

mysql-connector-java与Java对应版本

In view of the above, for beginners, they should directly use MySQL connector Java 8.0 or above