数据库配置,启动项目报错----The Server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one

数据库配置,启动项目报错----The Server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone

数据库配置,启动项目报错----The Server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone

这个错误的意思是服务器的区时不对

于是先百度了怎么修改mysql的区时:
首先需要查看MySQL的当前时区,用time_zone参数
通过命令查看当前时区:
show variables like ‘%time_zone%’;

mysql> show variables like '%time_zone%';   
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | CST    |
| time_zone        | SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)

这里显示time_zone 是SYSTEM,需要设置时区为东八区(北京区时)(为什么要这么设置:mysql使用的SYSTEM时区即EST时区,EST时区要比北京时间(东八区)慢13个小时)

直接通过命令修改
set global time_zone = timezone;
比如北京时间(GMT+0800)
set global time_zone = ‘+8:00’;


注:修改全局time_zone的值 ——set global time_zone=’+8:00’;
或 修改当前会话的time_zone 的值——set time_zone=’+8:00’;


#刷新权限使设置立即生效
flush privileges;

mysql> set global time_zone='+8:00';  
Query OK, 0 rows affected (0.00 sec)  
mysql> flush privileges; 
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.00 sec) 

再次启动项目不会报错,完美解决

以上是理想状态,但是如果不成功,还有第二种方法

这里我使用的是mysql-8.0.20-winx64,版本过高
之前我的数据库配置是这样的:

spring.datasource.url=jdbc:mysql://localhost:3306/你的数据库名?useUnicode=true&characterEncoding=utf-8
spring.datasource.username =root

这里的spring.datasource.url的----数据库名----后面需要做修改,修改后是这样的:

spring.datasource.url=jdbc:mysql://localhost:3306/你的数据库名?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=true
spring.datasource.username =root

或者使用这个:

?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8
  • 8
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值