The Format for Timestamps in MySQL Logs
source link: https://www.tuicool.com/articles/hit/22u2aqM
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
MySQL changed the timestamp format in the log files in MySQL 5.7. Since then, I have a few times seen questions about the new format, and how to change the time zone that is used. Latest in a comment to my blog about log_slow_extra
in 8.0.14 , where the question was what T and Z in the timestamp (for example 2019-01-31T07:24:06.100447Z
) means. In this blog, I will discuss the timestamp format and show you how you can change the time zone used.
The MySQL 5.7 Change
In MySQL 5.7 it was decided to make two changes to the timestamps affecting the format and time zone:
YYYY-MM-DDThh:mm:ss.uuuuuu
Tip
A couple of useful free resources, if you want to know more about the ISO 8601 / RFC 3339 format is the RFC specification and Wikipedia . The actual ISO 8601 specification can be purchased.
So there are two slightly different ways the timestamps can be displayed. The following two examples are for the default where the timestamp is in UTC and one where it is in UTC+11:00 (Australian Eastern Daylight Time):
2019-03-02T02:53:39.781592Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.15) starting as process 1516 2019-03-02T13:54:17.155810+11:00 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.15) starting as process 2812
Tip
In MySQL 8.0, you can also change the format itself, e.g. to JSON. See the MySQL reference manual on the error log format for for more information.
Changing the Time Zone
How do you change between the UTC and system time zones? You do that using the log_timestamps option which can take one of two values:
- UTC : Use UTC as the time zone. This is the default.
- SYSTEM : Use the same time zone as the operating system.
The option affects both the error log, slow query log, and general query log. The the slow and general query logs, though, it is only the case when logging to a file.
From XKCD comic 1179 .That Do T and Z Mean?
Back to the T and Z in the timestamps – what do they mean? The T is simply used as a separator between the data and time part. Think of it as T for Time. The Z means Zulu – another word for using the UTC time zone. That is:
- T : Separator between the data and time parts.
- Z : Zulu – the UTC time zone.
Thanks for reading.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK