数据库连接错误提示如下:
警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1fdce27 -- 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 (2). Last acquisition attempt exception:
java.sql.SQLException: The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
mysql 数据库连接参数如下
jdbc.driver = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql://localhost:3306/seckill
jdbc.username = root
jdbc.password = root
pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.5</version>
</dependency>
分析原因:
mysql 高版本里的时间区所导致的错误
解决办法
方法一:
使用低版本的mysql
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
方法二:
在 jdbc.url 后面加入 serverTimezone=UTC ,用了CTT中国台湾时区避免产生8小时时差
jdbc.url = jdbc:mysql://localhost:3306/seckill?serverTimezone=UTC
方法三:
修改本地 mysql 里的时间配置, mysql 里默认是 SYSTEM。
set global time_zone='+8:00'