玖叶教程网

前端编程开发入门

详解mysql数据库参数log_timestamps--控制日志记录使用的时区

概述

最近发现之前安装的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方面的内容,感兴趣的朋友可以关注下~

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言