问题描述

ERROR: Unable to create initial connections of pool.
问题一: 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.
问题二: Communications link failure
问题三: Unknown system variable ‘query_cache_size’

问题分析

mysql版本:8.0.15
问题一中的SSL问题需要通过在url配置中设置useSSL来解决。useSSL主要是用于mysql版本不匹配问题设置的,在mysql8.0以上版本一般由于兼容性问题都会用到这个配置。
基于以上出现的问题找了下解决方案,发现主要是由于mysql版本不匹配出现的问题。解决方案如下,主要有两处修改

问题解决
修改一: pom.xml
<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<scope>runtime</scope>
</dependency>

改成:

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

maven的jar包中mysql的版本配置为8.0.11,如下所示:
在这里插入图片描述

修改二: application.properties
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/harvest

改成:

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/harvest?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true

这样问题就解决了。


题外话:记录一下在sts中对maven的配置:
在这里插入图片描述

Logo

更多推荐