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:
- The format was changed to use the ISO 8601 / RFC 3339 format:
YYYY-MM-DDThh:mm:ss.uuuuuuplus a tail value to signify the time zone.
- The time zone used for the timestamps defaults to UTC (in 5.6 it defaulted to system time).
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
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.
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.