龙空技术网

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

波波说运维 176

前言:

今天小伙伴们对“mysql设置时区”大概比较珍视,你们都想要知道一些“mysql设置时区”的相关文章。那么小编在网摘上收集了一些对于“mysql设置时区””的相关知识,希望朋友们能喜欢,兄弟们快快来了解一下吧!

概述

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

标签: #mysql设置时区