大网数据广告活动
服务器运维问答

MySQL logs different time than NOW()

· 52CE 我爱测

MySQL server logs entries with different time than system or mysql itself: mysql> select @@global.time_zone; +--------------------+ | @@global.time_zone | +--------------------+ | SYSTEM | +--------------------+ mysql> select NOW…

问题原文

原帖链接 · aaaaa says reinstate Monica · CC BY-SA 3.0

MySQL server logs entries with different time than system or mysql itself:

mysql> select @@global.time_zone;
+--------------------+
| @@global.time_zone |
+--------------------+
| SYSTEM             |
+--------------------+
mysql> select NOW();
+---------------------+
| NOW()               |
+---------------------+
| 2016-02-24 10:47:30 |
+---------------------+

# /var/log/mysql/mysql_queries.log
2016-02-24T18:47:11.191126Z    2 Connect        root@localhost on  using Socket
2016-02-24T18:47:11.191421Z    2 Query  select @@version_comment limit 1
2016-02-24T18:47:16.769493Z    2 Query  select @@global.time_zone
2016-02-24T18:47:30.503214Z    2 Query  select NOW()

Timestamp seems synced with log:

mysql> show variables;
timestamp               | 1456339753.062182 # 18:47
log_timestamps          | UTC

已采纳解答

原帖链接 · aaaaa says reinstate Monica · CC BY-SA 3.0

Solution was super simple: look through the variables and try to locate relevant:

log_timestamps                   | UTC

So I changed it to 'SYSTEM':

mysql> SET GLOBAL  log_timestamps  = 'SYSTEM';

# /var/log/mysql/mysql_queries.log
2016-02-24T18:54:23.837289Z    2 Query  SET GLOBAL  log_timestamps  = 'SYSTEM'
2016-02-24T10:54:25.949232-08:00    2 Query     show variables

Time in log switched from 18:54 to 10:54 as should.

From MySQL docs:

  • log_timestamps

This variable controls the timestamp time zone of error log messages, and of general query log and slow query log messages written to files. It does not affect the time zone of general query log and slow query log messages written to tables (mysql.general_log, mysql.slow_log). Rows retrieved from those tables can be converted from the local system time zone to any desired time zone with CONVERT_TZ() or by setting the session time_zone system variable.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。