引言:
由于数据库MySQL版本升级(5.6 -> 8),SSM框架连接数据库时出现了一些问题,统一整理。
- 问题1:版本驱动问题
- 报错信息
21-Dec-2020 23:11:26.718 警告 [C3P0PooledConnectionPoolManager[identityToken->1hgeby9a7bdn9fp4fuljp|7985e39e]-HelperThread-#0] com.mchange.v2.resourcepool.BasicResourcePool. com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@15f4aab6 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:java.sql.SQLException: Unknown system variable 'query_cache_size'Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered v
- 解决方式
- 引入MySQL8.0的驱动版本
-
<!-- maven中修改驱动版本 8.0.11 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.11</version> </dependency> <!-- c3p0驱动版本 0.9.5.2 --> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</version> </dependency>
-
- 将配置文件的驱动更改为
-
com.mysql.cj.jdbc.Driver
-
- 引入MySQL8.0的驱动版本
- 解决方式
- 报错信息
- 问题2:不建议在没有服务器身份验证的情况下建立SSL连接
- 异常信息
Sat Dec 21 22:49:39 CST 2019 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.
- 解决方案
- 在连接后添加属性 &useSSL=false,为避免启动连接属性问题,建议直接使用以下属性
-
jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=Asia/Shanghai
各属性解释:&characterEncoding=utf8此属性设置utf8编码,处理乱码问题&serverTimezone=Asia/Shanghai此属性设置时区,可以统一设置为 UTC (全球标准时间)但是当使用java插入数据时会出现 实际插入时间和DB中的数据相差8小时,根本原因就是时区设置问题,我们国家使用的时区是 “东8区”,也就是领先UTC(全球标准时间8小时)所以,将时区统一设置为中国标准时间 Asia/Shanghai扩展 : java代码查询时区Calendar cal = Calendar.getInstance();TimeZone timeZone = cal.getTimeZone();System.out.println(timeZone.getID()); // Asia/ShanghaiSystem.out.println(timeZone.getDisplayName()); // 中国标准时间
-
- 在连接后添加属性 &useSSL=false,为避免启动连接属性问题,建议直接使用以下属性
- 异常信息