mysql时区_MySQL时区设置总结--参数system_time_zone和time_zone

概述

今天主要针对mysql时区这方面做一个总结,这里介绍两个参数:system_time_zone和time_zone。


01

全局参数system_time_zone

系统时区,在MySQL启动时会检查当前系统的时区并根据系统时区设置全局参数system_time_zone的值。

The system time zone. When the server starts, it attempts to determine the time zone of the host machine automatically and uses it to set thesystem_time_zone system variable. The value does not change thereafter.


02

全局参数time_zone

用来设置每个连接会话的时区,默认为system时,使用全局参数system_time_zone的值。

The current time zone. This variable is used to initialize the time zone for each client that connects. By default, the initial value of this is 'SYSTEM' (which means, “use the value of system_time_zone”).


03

参数log_timestamps

用于设置Error Log/Genaral Log/Slow Log这三种日志的时间信息。

有效值为UTC(默认)和SYSTEM(本地系统时区),当设置为system时,会使用参数system_time_zone的值。


04

修改参数time_zone

# 启动命令--default-time-zone=timezone# 配置文件default-time-zone=timezone# 运行期间set global time_zone='+8:00';
4a507866b66811d62db563b886d33dfb.png
334b0eb9ff5aa09008ad47198547cbd6.png

查看操作系统时区

#使用date命令date +"%Z %z"date -R## 使用timedatectltimedatectl|grep "Timezone"## 查看文件 /etc/timezonecat /etc/timezone
29d927ade44c3493637a7a5410f75d7f.png

ps:如果无法修改操作系统时区,又希望数据库使用其他时区,则可以使用参数time_zone来修改。


后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注一下~

810bb7fd7f98411b5d2150252af840c5.gif
  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Spring Boot中配置MySQL的serverTimezone可以通过在application.properties或application.yml文件中添加以下配置实现: 对于application.properties文件: ``` spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase?serverTimezone=Asia/Shanghai ``` 对于application.yml文件: ``` spring: datasource: url: jdbc:mysql://localhost:3306/mydatabase?serverTimezone=Asia/Shanghai ``` 在这里,serverTimezone属性设置MySQL时区为Asia/Shanghai。根据引用和引用的说明,serverTimezone属性设置会覆盖MySQLtime_zone变量,并确保Spring Boot会话的时区为东8区(Asia/Shanghai)。 此外,还可以使用系统的默认时区作为MySQL时区设置。根据引用,time_zone属性默认为System,即追随系统的时区设置。这意味着如果不显式地设置serverTimezone属性,MySQL将使用系统的默认时区作为服务器时区。 以上是关于在Spring Boot中配置MySQL的serverTimezone的方法。请根据您的具体需求选择适合的方式进行配置。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [SpringBoot mysql 时区问题总结](https://blog.csdn.net/zjy660358/article/details/117701956)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值