MySQL JDBC driver 8.0 configuration

1. Background

  As the MySQL version continues to iteratively upgrade, the corresponding driver must also be upgraded, so that some features of MySQL can be better used.

2. Driver update steps

   1. Version description

       mysql-connector-java   8.0.21

      mycat  1.6.75

    2. Configuration instructions

    mysql-connector-java version

<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>8.0.21</version>
</dependency>

    jdbc driver class: com.mysql.jdbc.Driver changed to com.mysql.cj.jdbc.Driver

    配置url: jdbc:mysql://192.168.11.11:6666/bm?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&serverTimezone=CST   

    Url note :  serverTimezone should correspond to   the time zone of the database

 3. Problems in the debugging process:

           A、java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

           Solution strategy:

                1) Communicate with DBA and understand the component versions used by each other (mycat, MySQL)

                2), add useSSL and serverTimezone time zone, such as   &useSSL=false&serverTimezone=CST     Note: serverTimezone should correspond to the time of the database

          B. When performing insert or update or query, sometimes these logs are output later: 

              (DruidAbstractDataSource.java:1488) - discard long time none received connection. , jdbcUrl : jdbc:mysql://XXXXXXX?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&serverTimezone=CST, jdbcUrl : jdbc:mysql://XXXXXXX?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&serverTimezone=CST, lastPacketReceivedIdleMillis : 301555

            Cause: The version of druid is higher . Lowering the version of druid can solve this prompt. as follows:

<dependency>
   <groupId>com.alibaba</groupId>
   <artifactId>druid</artifactId>
   <version>1.1.22</version>
</dependency>

Guess you like

Origin blog.csdn.net/baidu_28068985/article/details/109397893