SSM项目 MySQL版本升级到8.0 问题整理

引言:
    由于数据库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

             

  • 问题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/Shanghai
          System.out.println(timeZone.getDisplayName()); // 中国标准时间
           
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值