https://blog.csdn.net/leshami/article/details/78952842


在MySQL 5.7版本中,日志记录时间发生了变化,使用了UTC方式来记录日志时间,也就是说这是个世界统一时间,与我们常用的本地时间不协调,因此,初始化MySQL 5.7之后,需要对此做出调整,如下本文的描述。
一、错误日志的时间格式

当前环境
[robin@ydq-mnt ~]$ more /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[robin@ydq-mnt ~]$ mysql -V
mysql Ver 14.14 Distrib 5.7.19-17, for Linux (x86_64) using 6.2

[root@ydq-mnt ~]# date ###系统时间
Mon Dec 18 14:23:16 CST 2018

[root@ydq-mnt ~]# more /var/log/mysqld.log ###mysql 日志输出信息
2017-12-18T07:50:40.575098Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated.
Please use --explicit_defaults_for_timestamp server option (see do
cumentation for more details).
2017-12-18T07:50:40.576375Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.19-17-57-log) starting as process 9268 ...
2017-12-18T07:50:40.578287Z 0 [Warning] No argument was provided to --log-bin, and --log-bin-index was not used;
so replication may break when this MySQL serve
r acts as a master and has his hostname changed!! Please use '--log-bin=ydq-mnt-bin' to avoid this problem.
2017-12-18T07:50:40.578320Z 0 [Note] WSREP: Setting wsrep_ready to false
2017-12-18T07:50:40.578330Z 0 [Note] WSREP: No pre-stored wsrep-start position found. Skipping position initialization.
2017-12-18T07:50:40.578335Z 0 [Note] WSREP: wsrep_load(): loading provider library '/usr/lib64/galera3/libgalera_smm.so'
2017-12-18T07:50:40.582014Z 0 [Note] WSREP: wsrep_load(): Galera 3.22(r8678538) by Codership Oy
<info@codership.com> loaded successfully.
从上所示,当前的系统时间为mysql日志记录的时间不一致。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

二、系统变量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.
从上描述可知,这个变量是在MySQL 5.7.2中添加的。缺省值为UTC。
如果如要使用缺省时区的时间,修改该参数的值为SYSTEM

1
2
3
4
5
6
7
8
9
10
11
12
13

三、修改及验证

mysql> set global log_timestamps='SYSTEM';
Query OK, 0 rows affected (0.00 sec)

[root@ydq-mnt mysql]# vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf
log_timestamps=SYSTEM

[root@ydq-mnt ~]# systemctl restart mysql
2017-12-18T07:52:41.543983Z 0 [Note] Beginning of list of non-natively partitioned tables
2017-12-18T07:52:41.544128Z 0 [Note] WSREP: Member 0.0 (ydq-mnt) synced with group.
2017-12-18T07:52:41.544138Z 0 [Note] WSREP: Shifting JOINED -> SYNCED (TO: 4163)
2017-12-18T07:52:41.550738Z 8 [Note] WSREP: Synchronized with group, ready for connections
2017-12-18T07:52:41.550755Z 8 [Note] WSREP: This node is synced, setting wsrep_ready to true
2017-12-18T07:52:41.550761Z 8 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
2017-12-18T07:52:41.582207Z 0 [Note] End of list of non-natively partitioned tables
2017-12-18T07:52:43.178826Z 0 [Note] InnoDB: Buffer pool(s) load completed at 171218 15:52:43
2017-12-18T16:24:23.588881+08:00 0 [Note] WSREP: Received shutdown signal. Will sleep for 10 secs before initiating shutdown.
pxc_maint_mode switched to SHUTDOWN
2017-12-18T16:24:33.591354+08:00 0 [Note] WSREP: Stop replication
2017-12-18T16:24:33.591408+08:00 0 [Note] WSREP: Closing send monitor...
2017-12-18T16:24:33.591429+08:00 0 [Note] WSREP: Closed send monitor.
2017-12-18T16:24:33.591453+08:00 0 [Note] WSREP: gcomm: terminating thread
2017-12-18T16:24:33.591477+08:00 0 [Note] WSREP: gcomm: joining thread
2017-12-18T16:24:33.591700+08:00 0 [Note] WSREP: gcomm: closing backend
再次启动及验证,时间显示与系统时间一致。
---------------------

MySQL 5.7 时间显示修改(log_timestamps UTC)的更多相关文章

  1. jsp页面上读取MySQL数据库datetime时间显示问题

    mysql数据库中时间字段选用了datetime,如果通过java实现在jsp页面上显示时间为"年-月-日  时:分"等格式,那么如下代码就会有不同的结果! 实体类中两个变量: p ...

  2. MySql的创建时间和修改时间

      在创建时间字段的时候 DEFAULT CURRENT_TIMESTAMP表示当插入数据的时候,该字段默认值为当前时间 ON UPDATE CURRENT_TIMESTAMP表示每次更新这条数据的时 ...

  3. Centos修改时间显示的时区,将UTC修改为CST

    问题说明: 今天一同事反应,系统的时间不对和正常的时间差8个小时.就登录主机看了下时间 系统时间显示为: # date Fri Dec :: UTC # 备注:查看了下,正好和当前的时间差了8个小时. ...

  4. Xiuno BBS 4.0 修改时间显示

    修罗开源轻论坛程序 - Xiuno BBS 4.0Xiuno BBS 4.0 是一款轻论坛产品,前端基于 BootStrap 4.0.JQuery 3,后端基于 PHP/7 MySQL XCache/ ...

  5. Windows 修改个性化时间显示

    A goal is a dream with a deadline. Much effort, much prosperity. 我感觉我的时间显示不够人性化.不够个性化 修改注册表 我的系统为Win ...

  6. MySQL 5.7贴心参数之 log_timestamps

    写在前面 使用 MySQL 的过程中,经常会有人碰到这么一个问题,看错误日志.慢查询日志的时候,时间总是和本地时间对不上,差了 8 个小时,这样分析起来就相对麻烦了一些. 新改进 对于不知道是什么原因 ...

  7. MySQL5.7 error log时间显示问题

    最近有两三套环境升级到了5.7.16,发现mysql.err中的时间好像有些问题,经查是mysql 5.7后的变更,如下: root@localhost [(none)]>select now( ...

  8. MySQL日期和时间类型笔记

    最近在看<MySQL技术内幕:SQL编程>并做了笔记,这是一篇笔记类型博客,分享出来方便自己复习,也可以帮助其他人 一.日期时间类型所占空间对比 各种日期时间数据类型所占的空间: 类型 所 ...

  9. MySQL 获得当前日期时间\时间戳 函数 ( 转自传智播客)

    MySQL 获得当前日期时间 函数 1.1 获得当前日期+时间(date + time)函数:now() mysql> select now(); +-------+ | now() | +-- ...

随机推荐

  1. [InfluxDB] 安装与配置

    [InfluxDB] 安装与配置 1- 下载 ubtuntu: wget https://dl.influxdata.com/influxdb/releases/influxdb_1.5.2_amd6 ...

  2. html多个水平并列组件自适应等高的做法

    做一个div盒子,设置over-flow:hidden,设置高度为auto.然后再盒子里排列若干inline-block,inline元素. 自适应的话常用做法是用line-height,font-s ...

  3. ALGO-123_蓝桥杯_算法训练_A+B problem

    问题描述 Given two integers A and B, your task is to output their sum, A+B. 输入格式 The input contains of o ...

  4. 使用googletest进行C++单元测试(Netbeans为例)

    googletest设置步骤(Netbeans为例) 下载googletest [https://github.com/google/googletest],解压到<gtest_dir> ...

  5. 函数,lambda函数,递归函数,内置函数(map,filter),装饰器

    1. 集合 主要作用: 去重 关系测试, 交集\差集\并集\反向(对称)差集 2. 元组 只读列表,只有count, index 2 个方法 作用:如果一些数据不想被人修改, 可以存成元组,比如身份证 ...

  6. Nodejs使用多个分隔符分隔字符串

    在nodejs中当需要使用多个分隔符分隔字符串时,可以使用正则表达式作为split函数的参数,具体使用如下: var str = "111@222#333 444@555# 666 777& ...

  7. Spring的LoadTimeWeaver(代码织入)(转)

    https://www.cnblogs.com/wade-luffy/p/6073702.html 在Java 语言中,从织入切面的方式上来看,存在三种织入方式:编译期织入.类加载期织入和运行期织入. ...

  8. github_源码

      固定头部: hongyangAndroid/Android-StickyNavLayout:ListView 与ViewPager 滑动冲突处理,滑动到顶部固定位置停顿; ufo22940268/ ...

  9. [UE4]多线程开关,开启的解决方案

    像这样直接获取值就会被警告. 解决方法:定义一个变量speed,然后在“Blueprint Update Animation”事件中赋值给这个变量. 这样就不会被警告了. 另外一种解决方法:就是关掉多 ...

  10. arcgis for android 读取shp文件中文乱码解决方法

    设置注册表默认字符,即可解决中文乱码问题. 'dbfDefault' 设置方法1.开始--运行,输入”Regedit“,打开注册表.2.如是用的是 10.x 版本 ArcGIS Desktop,定位到 ...