java.sql.SQLException: The server time zone value xxx
- mysql默认的时区和本地时区不一致导致的
- 有多个时区,运行时需要指定一个时区
方案一:修改mysql默认时区
1.查询系统支持当前的时区设置:
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.12|
+-----------+
1 row in set (0.00 sec)
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name| Value|
+------------------+--------+
| system_time_zone | CST|
| time_zone| SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)
2.修改时区设置:
方法1:写入到配置文件需要重启mysql实例:
[mysqld]
default-time-zone=timezone
修改为
default-time-zone = '+8:00'
方法2:在线修改和查看:
mysql> set time_zone='+8:00';
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name| Value|
+------------------+--------+
| system_time_zone | CST|
| time_zone| +08:00 |
+------------------+--------+
2 rows in set (0.01 sec)
--通过now() 查看:
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name| Value|
+------------------+--------+
| system_time_zone | CST|
| time_zone| +08:00 |
+------------------+--------+
2 rows in set (0.01 sec)
mysql> select now();
+---------------------+
| now()|
+---------------------+
| 2018-08-28 16:08:38 |
+---------------------+
1 row in set (0.00 sec)
mysql> set time_zone='+0:00';
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name| Value|
+------------------+--------+
| system_time_zone | CST|
| time_zone| +00:00 |
+------------------+--------+
2 rows in set (0.01 sec)
mysql> select now();
+---------------------+
| now()|
+---------------------+
| 2018-08-28 08:09:12 |
+---------------------+
1 row in set (0.00 sec)
--自MySQL 8.0 GA版本开始支持将参数写入并且持久化:
mysql> set persist time_zone='+0:00';
--针对application 可以设置:
jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&autoReconnect=true&serverTimezone=UTC
--结论:
mysql> set time_zone='+8:00';
和time_zone='system'是等同的,默认为系统时间。
方案二:连接mysql时指定时区为UTC
jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC
Failed to load property source from location ‘classpath:/application.yml’
- yml的语法格式有误
application.yml:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8
datasource:
type: com.alibaba.druid.pool.DruidDataSource
解决方法:修改后的application.yml:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8
type: com.alibaba.druid.pool.DruidDataSource
PS:校验yml语法
注:注意缩进
- 其他问题
spring:
datasource:
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8
username: root
password: 123456
servlet:
multipart:
max-file-size: 5MB # 限制文件上传的大小
从配置文件中可以看出语法并无问题。
解决办法:
- File–>Settings–>File Encodings
- 如第一步并未解决问题,则可以用终极杀招(本人就是加了中文注释)。
spring-boot-starter-thymeleaf版本问题 spring boot默认thymeleaf版本是2.1.1
修改为:3.0.11.RELEASE就OK啦!
3.0.11.RELEASE
2.1.1
org.springframework.boot
spring-boot-starter-thymeleaf
【SpringBoot|SpringBoot 学习过程遇到的问题】参考:
https://my.oschina.net/u/3740271/blog/3028874;
https://blog.csdn.net/vkingnew/article/details/82149726 ;
https://blog.csdn.net/qq_37495786/article/details/82505737;
推荐阅读
- 第五节:SpringBoot常用注解介绍
- 第四节:SpringBoot中web模版数据渲染展示
- SpringBoot2022【草稿】
- 聊聊springboot项目全局异常处理那些事儿
- 第一节:创建SpringBoot项目并运行HelloWorld
- springboot管理系统[基于员工角色和文件权限的分级的后台管理系统源码]
- SpringBoot之@ComponentScan和@SpringBootApplication扫描覆盖问题
- mybatis|记mybatis查询null字段导致的NPE
- SpringBoot|SpringBoot 整合 druid数据源
- springboot项目配置application添加图片映射 (windows and linux 都可使用)