MySQL5.7参数log_timestamps

最近测试MySQL 5.7.21  Community Server这个版本的MySQL数据库时,发现其错误日志的时间跟系统当前时间不一致,后面检查发现日期时间格式都是UTC时间,查了一下相关资料,原来在MySQL 5.7.2 之后日志文件里面的时间戳从默认的本地系统时区改为了UTC格式。MySQL 5.7.2多了一个参数log_timestamps ,这个参数主要是控制错误日志、慢查询日志等日志中的显示时间。但它不会影响查询日志和慢日志写到表 (mysql.general_log, mysql.slow_log) 中的显示时间。在查询记录的时候,可以使用 CONVERT_TZ() 函数,或者设置会话级别的系统变量 time_zone 来转换成所需要的时区。官方资料详细介绍如下所示:

This variable controls the time zone of timestamps in messages written to the error log, and in 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.

此参数是全局的,可以动态修改,修改参数log_timestamps的值非常简单,如下所示,不过最好在参数文件my.cnf设置该参数值,以防MySQL服务重启失效。

mysql> show variables like ‘log_timestamps‘;
+----------------+-------+

| Variable_name  | Value |

+----------------+-------+

| log_timestamps | UTC   |

+----------------+-------+

1 row in set (0.01 sec)

 

mysql> set global log_timestamps=system;

Query OK, 0 rows affected (0.00 sec)

 

mysql> show variables like ‘log_timestamps‘;

+----------------+--------+

| Variable_name  | Value  |

+----------------+--------+

| log_timestamps | SYSTEM |

+----------------+--------+

1 row in set (0.01 sec)

 

mysql>

参考资料:

http://mysql.taobao.org/monthly/2017/01/09/

https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_log_timestamps

原文地址:https://www.cnblogs.com/kerrycode/p/8974049.html

时间: 2024-08-01 19:24:36

MySQL5.7参数log_timestamps的相关文章

MySQL 5.7 参数 – log_timestamps

http://www.ttlsa.com/mysql/mysql-5-7-kengdieparam-log_timestamps/ 官网原话: 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 m

MySQL5.6参数binlog-do-db和log-slave-updates跨库同步注意事项

MySQL5.6.20上在master主库配置文件/etc/my.cnf里指定数据库同步到slave从库上使用参数binlog-do-db log-slave-updates 注意事项: 一. master主库上binlog-format = MIXED为混合模式时 mysql master主库:/etc/my.cnf 当binlog-format = MIXED 位混合模式时:1.1配置文件参数: [[email protected] etc]# egrep "binlog-format|se

mysql5.7 参数记录 (持续更新)

sync_binlog 控制数据库的binlog刷到磁盘 默认sync_binlog=1,表示每次事务提交,MySQL都会把binlog刷下去,是最安全但是性能损耗最大的设置. sync_binlog=100或者是0.牺牲一定的一致性,可以获得更高的并发和性能. innodb_flush_log_at_trx_commit 控制log_buffer刷到磁盘   0  每次提交事务log_buffer不写入log_file  1 每次提交事务log_buffer写入log_file,默认配置  2

windows 7 本机已安装mysql5的情况下安装XAMPP

这篇其实是编程无关的技术贴. 近期想接触学习一下PHP,手里的电脑是windows7系统的笔记本,懒得为了这点需要去装linux或者虚拟机搞火到不行的LAMP,找到了XAMPP,XAMPP是一个把Apache网页服务器与PHP.Perl及MySQL集合在一起的安装包,允许用户可以在自己的电脑上轻易的建立网页服务器. 于是问题来了,之前搞JAVA EE时电脑上装了mysql5.1,但是XAMPP中也安装了mysql,版本是5.6,怎么保证在XAMPP的mysql使用正常的情况下,原先的JAVA E

CentOS7一键编译安装LNMP环境

#!/bin/sh #!/bin/sh #author: vim #qq: 82996821 #OS: Centos7.2 #filename: auto_install_lnmp.sh #init variable PHP_VERSION='7.0.20'    #PHP版本号 NGINX_VERSION='1.10.3'    #NGINX版本号 TOOL_DIR=`pwd` APP_INSTALL_DIR='/usr/local'    #服务安装路径 DATA_DIR='/data'  

mysql 5.7主从安装和配置

本文主要介绍mysql 5.7主从复制,转载请注明出处 下载地址 模块 版本 下载地址 mysql 5.7 https://dev.mysql.com/downloads/mysql/ libaio(可选) 0.3.110 http://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus/x86_64/RPMS.classic//libaio-0.3.110-alt1.1.x86_64.rpm net-tools(可选) 2.0.22 htt

MySQL5.7配置参数

MySQL5.7的参数调整配置,参考例子,某些具体参数的设置还需要根据实际来调整. [client] port                            = 3306 socket                          = /tmp/mysql3306.sock default_character_set           = utf8mb4 [mysqld] lower_case_table_names   = 1 port                      

mysql5.7新增参数配置解释

1:binlog_group_commit_sync_delay 全局动态变量,单位微妙,默认0,范围:0-1000000(1秒). 表示binlog提交后等待延迟多少时间再同步到磁盘,默认0,不延迟.设置延迟可以让多个事务在用一时刻提交,提高binlog组提交的并发数和效率,提高slave的吞吐量. 2:binlog_group_commit_sync_no_delay_count 全局动态变量,单位个数,默认0,范围:0-1000000. 表示等待延迟提交的最大事务数,如果上面参数的时间没到

MySQL5.7中 performance和sys schema中的监控参数解释

MySQL5.7中的mysql  performance和sys 监控参数 1.performance schema:介绍 在MySQL5.7中,performance schema有很大改进,包括引入大量新加入的监控项.降低占用空间和负载,以及通过新的sys schema机制显著提升易用性.在监控方面,performance schema有如下功能: ①:元数据锁: 对于了解会话之间元数据锁的依赖关系至关重要.从MySQL5.7.3开始,就可以通过metadata_locks表来了解元数据锁的