Skip to content
鼓励作者:欢迎打赏犒劳

05-服务器时区

如何分区当前环境是哪个时区?

window

shell
systeminfo | findstr "时区"

mac

shell
ls -la /etc/localtime

Linux

shell
ls -la /etc/localtime

mysql查询时区

mysql有独立的时区设置,MySQL 不会自动使用系统时区:

sql
-- 查看当前时区设置
SELECT @@global.time_zone, @@session.time_zone;

-- 查看当前时间
SELECT NOW(), UTC_TIMESTAMP();

-- 设置时区(需要权限)
SET GLOBAL time_zone = '+08:00';
SET time_zone = '+08:00';

或者在 my.cnf 中配置:

shell
[mysqld]
default-time-zone = '+08:00'

如有转载或 CV 的请标注本站原文地址