JDBC connection mysql8 and mysql5.7 attention

1. com.mysql.jdbc.Driver is obsolete and cannot be used. You should use the new driver class com.mysql.cj.jdbc.Driver

2. When writing the connection path url, add the time zone at the end, and the version above mysql8 adds the time zone setting serverTimezone

jdbc:mysql://localhost:3306/test01?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai

3. jboss changes the mysql driver package, you need to change both server\default\lib and server\default\deploy\your own package\WEB-INF\lib\ 

Driver 8.0 needs jdk1.8+, 5.1.46 can satisfy both jdk version and mysql library is 8 and 5.7

Verified 5.1.46, both 1.7jdk and mysql8 can be connected

---------The following is reproduced from: Correspondence between mysql driver, database and jdk versions- upstreamL - Blog Garden

There is still a certain relationship between the mysql driver and the jdk version. After on-site measurement and search data, the records are as follows:

Application JDK version 1.5 Test environment MySQL version 5.7 Driver version 5.1.40.jar Normal

                            The MySQL version 8.0 driver version 5.1.40.jar in the production environment cannot be connected

                            The production environment MySQL version 8.0 driver version 8.0.11.jar reports that the JDK version is too low

Application JDK8 production environment MySQL version 8.0 driver version 8.0.11.jar normal

Application JDK8 production environment MySQL version 5.7 driver version 8.0.11.jar normal

Apply JDK1.7 mysql library 5.7 driver 5.1.38 normal

Application of JDK1.7 mysql library 8 driver 5.1.38 does not work

Apply JDK1.7 mysql library 8 driver 5.1.46 normal

Apply JDK1.7 mysql library 5.7 driver 5.1.46 normal

Apply JDK1.7 mysql library 8 driver 5.1.46 normal

Application of JDK1.7 mysql library 8 driver 8.0.11 does not work

Application of JDK1.7 mysql library 5.7 driver 8.0.11 does not work

Apply JDK1.8 mysql library 8 driver 8.0.11 normal

Summary: Driver 8.0 needs jdk1.8+, and 5.1.46 can satisfy both jdk version and mysql library, 8 and 5.7, which are better!

References from others:

 Connector/J5.1 requires JRE 1.8.x to connect to MySQL 5.6, 5.7 and 8.0 using SSL/TLS when certain cipher suites are used.

Guess you like

Origin blog.csdn.net/myfmyfmyfmyf/article/details/125235791