启动web项目报错:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone.

解决:

在application.properties配置文件中的添加标红部分

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/miaosha?serverTimezone=UTC

https://www.cnblogs.com/gabriel-y/p/11888270.html

Jdbc Driver驱动和ServerTimeZone时区的的问题


 

一.JDBC驱动的版本号以及名称问题

区别:

  com.mysql.jdbc.Driver 是 mysql-connector-java 5中的

  com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6以上的版本中的

注意,我这里使用的是springboot2.1.1版本,在pom.xml文件中整合mysql后自动引入的mysql-connector-java版本是8.x,因此需要使用com.mysql.cj.jdbc.Driver 这个驱动

如图:

复制代码
    <!-- springboot版本-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    <!-- 省略其他依赖-->
    
    <!-- mysql 这里没有显示的指定版本,默认集成的版本是8.x-->
    <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
    </dependency>      
复制代码

注意:如果使用 com.mysql.jdbc.Driver,项目启动时,控制台会报错,表示该驱动已经过时

二.ServerTimeZone时区的问题

在设定时区的时候,如果设定serverTimezone=UTC,会比中国时间早8个小时,如果在中国,可以选择Asia/Shanghai或者Asia/Hongkong,例如:

url:jdbc:mysql://localhost:3306/mango?serverTimezone=Asia/Shanghai&useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=utf-8

注意:

   如果在url这里不设置时区,则可能报错

三.服务器直连mysq问题

不推荐不使用服务器身份验证来建立SSL连接。SSL – Secure Sockets Layer(安全套接层)


如果未明确设置,MySQL 5.5.45+, 5.6.26+ and 5.7.6+版本默认要求建立SSL连接。


为了符合当前不使用SSL连接的应用程序,verifyServerCertificate属性设置为’false’。或者使用autoConnect=true显示的支持直连
如果你不需要使用SSL连接,你需要通过设置useSSL=false来显式禁用SSL连接
如果你需要用SSL连接,就要为服务器证书验证提供信任库,并设置useSSL=true。


第二种:修改MySQL数据库的时区

net start mysql

mysql -u root -p 密码


show variables like '%time_zone%';


set global time_zone='+8:00';




 
原文地址:https://www.cnblogs.com/JimShi/p/11897573.html