SpringBoot连接数库错误ava.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or repr

报的错误信息:ava.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.

pom.xml配置:

<!-- mysql 数据库驱动 -->
	<dependency>
	  	<groupId>mysql</groupId> 
	  	<artifactId>mysql-connector-java</artifactId> 
	 </dependency>
	<!-- druid 数据库连接池 -->
	<dependency>
	    <groupId>com.alibaba</groupId>
	    <artifactId>druid</artifactId>
	    <version>1.1.12</version>
	</dependency>

application.properties:

# druid
# 数据库相关连接设置
spring.datasource.url=jdbc:mysql://localhost:3306/miaosha?serverTimezone=CTT&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
# druid 相关设置
spring.datasource.filters=stat
spring.datasource.maxActive=2
spring.datasource.initialSize=1
spring.datasource.maxWait=60000
spring.datasource.minIdle=1
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=select 'x'
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
spring.datasource.poolPreparedStatements=true
spring.datasource.maxOpenPreparedStatements=20

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 本来用的 com.mysql.jdbc.Driver报了警告,因此更改。

原因:

           连接数据中时区错误原因

解决:

     加上  serverTimezone=UTC

      这里用了CTT中国台湾时区避免产生8小时时差

spring.datasource.url=jdbc:mysql://localhost:3306/miaosha?serverTimezone=CTT&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
发布了159 篇原创文章 · 获赞 86 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/qq_40301026/article/details/98532053