詳解mysql資料庫參數log_timestamps--控制日誌記錄使用的時區

2019-11-06     波波說運維

概述

最近發現之前安裝的MySQL 5.7.27,其中的error log、general log日誌裡面日誌時間的時區不對。


思路:

mysql 5.7.2新增了參數 log_timestamps,用於控制error log、general log、slow log日誌記錄使用的時區,只影響寫入文件的時區,不影響寫入表中記錄的時區。默認值是UTC,支持設置為SYSTEM使用系統的時區。

• 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.

Permitted log_timestamps values are UTC (the default) and SYSTEM (local system time zone). Timestamps are written using ISO 8601 / RFC 3339 format: YYYY-MM-DDThh:mm:ss.uuuuuu plus a tail value of Z signifying Zulu time (UTC) or ±hh:mm (an offset from UTC).

This variable was added in MySQL 5.7.2. Before 5.7.2, timestamps in log messages were written using the local system time zone by default, not UTC. If you want the previous log message time zone default, set log_timestamps=SYSTEM.


解決:

1、臨時修改

set global log_timestamps=SYSTEM;

執行之後,新的日誌的時區就會變成系統默認的時區。

2、永久修改

在my.cnf中添加 log_timestamps=SYSTEM


覺得有用的朋友多幫忙轉發哦!後面會分享更多devops和DBA方面的內容,感興趣的朋友可以關注下~

文章來源: https://twgreatdaily.com/7V08Pm4BMH2_cNUgTa3H.html