在MySQL 5.7版本中掖举,日志記錄時(shí)間發(fā)生了變化濒旦,使用了UTC方式來(lái)記錄日志時(shí)間纫谅,也就是說(shuō)這是個(gè)世界統(tǒng)一時(shí)間炫贤,與我們常用的本地時(shí)間不協(xié)調(diào),因此系宜,初始化MySQL 5.7之后照激,需要對(duì)此做出調(diào)整,如下本文的描述盹牧。
一俩垃、錯(cuò)誤日志的時(shí)間格式
當(dāng)前環(huán)境
[robin@ydq-mnt ~]$ more /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[robin@ydq-mnt ~]$ mysql -V
mysql Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using EditLine wrapper
[root@ydq-mnt ~]# date ###系統(tǒng)時(shí)間
2018年 07月 25日 星期三 12:53:32 CST
[root@ydq-mnt ~]# more /var/log/mysqld.log ###mysql 日志輸出信息
2018-07-25T07: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).
2018-07-25T07:50:40.576375Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.22-17-57-log) starting as process 9268 ...
2018-07-25T07: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.
2018-07-25T07:50:40.578320Z 0 [Note] WSREP: Setting wsrep_ready to false
2018-07-25T07:50:40.578330Z 0 [Note] WSREP: No pre-stored wsrep-start position found. Skipping position initialization.
2018-07-25T07:50:40.578335Z 0 [Note] WSREP: wsrep_load(): loading provider library '/usr/lib64/galera3/libgalera_smm.so'
2018-07-25T07:50:40.582014Z 0 [Note] WSREP: wsrep_load(): Galera 3.22(r8678538) by Codership Oy loaded successfully.
從上所示,當(dāng)前的系統(tǒng)時(shí)間為mysql日志記錄的時(shí)間不一致汰寓。
二口柳、系統(tǒng)變量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.
從上描述可知,這個(gè)變量是在MySQL 5.7.2中添加的有滑。缺省值為UTC跃闹。
如果如要使用缺省時(shí)區(qū)的時(shí)間,修改該參數(shù)的值為SYSTEM
三毛好、修改及驗(yàn)證
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
2018-07-25T07:52:41.543983Z 0 [Note] Beginning of list of non-natively partitioned tables
2018-07-25T07:52:41.544128Z 0 [Note] WSREP: Member 0.0 (ydq-mnt) synced with group.
2018-07-25T07:52:41.544138Z 0 [Note] WSREP: Shifting JOINED -> SYNCED (TO: 4163)
2018-07-25T07:52:41.550738Z 8 [Note] WSREP: Synchronized with group, ready for connections
2018-07-25T07:52:41.550755Z 8 [Note] WSREP: This node is synced, setting wsrep_ready to true
2018-07-25T07:52:41.550761Z 8 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
2018-07-25T07:52:41.582207Z 0 [Note] End of list of non-natively partitioned tables
2018-07-25T07:52:43.178826Z 0 [Note] InnoDB: Buffer pool(s) load completed at 171218 15:52:43
2018-07-25T16: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
2018-07-25T16:24:33.591354+08:00 0 [Note] WSREP: Stop replication
2018-07-25T16:24:33.591408+08:00 0 [Note] WSREP: Closing send monitor...
2018-07-25T16:24:33.591429+08:00 0 [Note] WSREP: Closed send monitor.
2018-07-25T16:24:33.591453+08:00 0 [Note] WSREP: gcomm: terminating thread
2018-07-25T16:24:33.591477+08:00 0 [Note] WSREP: gcomm: joining thread
2018-07-25T16:24:33.591700+08:00 0 [Note] WSREP: gcomm: closing backend
再次啟動(dòng)及驗(yàn)證望艺,時(shí)間顯示與系統(tǒng)時(shí)間一致。