MySQL/TIMESTAMP:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第8行: 第8行:
time_zone SYSTEM
time_zone SYSTEM
</syntaxhighlight>||mysql>}}
</syntaxhighlight>||mysql>}}
设置为东八区(中国时区)
{{shc|<syntaxhighlight lang="bash">
SET GLOBAL time_zone = '+8:00';
</syntaxhighlight>||mysql>}}
== 自动时间管理 ==
<syntaxhighlight lang="mysql">
CREATE TABLE example (
  id INT AUTO_INCREMENT PRIMARY KEY,
  create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,          -- 插入时自动填充当前时间
  update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP  -- 插入和更新时均自动填充
);</syntaxhighlight>


== 时区转换 ==
== 时区转换 ==

2025年12月19日 (五) 15:32的版本

标题文本

查看当前时区

mysql>
SHOW VARIABLES LIKE '%time_zone%';
Variable_name	Value
system_time_zone	UTC
time_zone	SYSTEM

设置为东八区(中国时区)

Bash-icon-svgrepo-com.svg
mysql>
SET GLOBAL time_zone = '+8:00';

自动时间管理

CREATE TABLE example (
  id INT AUTO_INCREMENT PRIMARY KEY,
  create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,          -- 插入时自动填充当前时间
  update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP  -- 插入和更新时均自动填充
);

时区转换