Detailed explanation of the reason why the MySQL 5.7 slow query log time is 8 hours behind the system time

Detailed explanation of the reason why the MySQL 5.7 slow query log time is 8 hours behind the system time

When checking the slow query, I found that the time was incorrect, which was exactly 8 hours different from the system time.

1. The slow query display time is as follows

# Time: 2020-01-10T06:42:24.940811Z

2. System time

$ date
Fri Jan 10 14:42:31 CST 2020

3. View database parameters

mysql> show variables like 'log_timestamps';
+----------------+-------+
| Variable_name | Value |
+----------------+-------+
| log_timestamps | UTC |
+----------------+-------+
1 row in set (0.00 sec)

As we all know, UTC is the unified universal time, and my current system time is East 8, which is 8 hours ahead of UTC, so it is correct. Check the official documentation for the explanation on the official website.

log_timestamps

Property Value
Command-Line Format --log-timestamps=#
Introduced 5.7.2
System Variable log_timestamps
Scope Global
Dynamic Yes
Type Enumeration
Default Value UTC
Valid Values
UTC

SYSTEM

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).

Modifying the parameters can solve the problem.

mysql> SET GLOBAL log_timestamps = SYSTEM;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW GLOBAL VARIABLES LIKE 'log_timestamps';
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| log_timestamps | SYSTEM |
+----------------+--------+

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • MySQL calculates the number of days, months, and years between two dates
  • mysql calculate time difference function
  • Implementation of removing overlapping time and calculating time difference in MySQL
  • How to get the time difference between two times in mysql query

<<:  Nginx load balancing configuration, automatic switching mode when downtime occurs

>>:  Vue Beginner's Guide: Environment Building and Getting Started

Recommend

Mysql method to copy a column of data in one table to a column in another table

mysql copy one table column to another table Some...

Ubuntu20.04 VNC installation and configuration implementation

VNC is a remote desktop protocol. Follow the inst...

Steps for encapsulating element-ui pop-up components

Encapsulate el-dialog as a component When we use ...

Difference and principle analysis of Nginx forward and reverse proxy

1. The difference between forward proxy and rever...

Talking about Less and More in Web Design (Picture)

Less is More is a catchphrase for many designers....

Causes and solutions for slow MySQL queries

There are many reasons for slow query speed, the ...

Vue-CLI3.x automatically deploys projects to the server

Table of contents Preface 1. Install scp2 2. Conf...

Ubuntu16.04 builds php5.6 web server environment

Ubuntu 16.04 installs the PHP7.0 environment by d...

HTML Tutorial: Collection of commonly used HTML tags (5)

These introduced HTML tags do not necessarily ful...

A brief analysis of MySQL backup and recovery

Table of contents 1. Introduction 2. Simple defin...

Detailed example of deploying Nginx+Apache dynamic and static separation

Introduction to Nginx dynamic and static separati...

Solutions to invalid is Null segment judgment and IFNULL() failure in MySql

MySql Null field judgment and IFNULL failure proc...

19 MySQL optimization methods in database management

After MySQL database optimization, not only can t...