I have always wondered why the startView the current database time zone mysql> show variables like "%time_zone%"; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | CST | | time_zone | +08:00 | +------------------+--------+ 2 rows in set (0.30 sec) View table structure mysql> desc timestamp_test; +--------------+-----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+-----------+------+-----+---------+----------------+ | id | int | NO | PRI | NULL | auto_increment | | created_time | datetime | YES | | NULL | | | created_at | timestamp | YES | | NULL | | +--------------+-----------+------+-----+---------+----------------+ 3 rows in set (0.26 sec) Inserting Data mysql> insert into timestamp_test(created_time, created_at) values('2020-12-09 08:00:00', '2020-12-09 08:00:00'); Query OK, 1 row affected (0.22 sec) mysql> select * from timestamp_test; +----+---------------------+---------------------+ | id | created_time | created_at | +----+---------------------+---------------------+ | 1 | 2020-12-09 08:00:00 | 2020-12-09 08:00:00 | +----+---------------------+---------------------+ 1 row in set (0.06 sec) This time seems to be correct, so let's try to change the time zone and insert the data again. mysql> SET time_zone = "+00:00"; Query OK, 0 rows affected (0.03 sec) mysql> insert into timestamp_test(created_time, created_at) values('2020-12-09 08:00:00', '2020-12-09 08:00:00'); Query OK, 1 row affected (0.03 sec) mysql> SET time_zone = "+08:00"; Query OK, 0 rows affected (0.04 sec) Now check the data again. The two inserted mysql> select * from timestamp_test; +----+---------------------+---------------------+ | id | created_time | created_at | +----+---------------------+---------------------+ | 1 | 2020-12-09 08:00:00 | 2020-12-09 08:00:00 | | 2 | 2020-12-09 08:00:00 | 2020-12-09 16:00:00 | +----+---------------------+---------------------+ 2 rows in set (0.06 sec) Let's take a look at the timestamp actually stored. Then we change the time zone and find that the field time has changed, but the original timestamp data has not changed. mysql> select *, unix_timestamp(created_at) from timestamp_test; +----+---------------------+---------------------+----------------------------+ | id | created_time | created_at | unix_timestamp(created_at) | +----+---------------------+---------------------+----------------------------+ | 1 | 2020-12-09 08:00:00 | 2020-12-09 08:00:00 | 1607472000 | | 2 | 2020-12-09 08:00:00 | 2020-12-09 16:00:00 | 1607500800 | +----+---------------------+---------------------+----------------------------+ 2 rows in set (0.06 sec) mysql> SET time_zone = "+00:00"; Query OK, 0 rows affected (0.09 sec) mysql> show variables like "%time_zone%"; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | CST | | time_zone | +00:00 | +------------------+--------+ 2 rows in set (0.08 sec) mysql> select *, unix_timestamp(created_at) from timestamp_test; +----+---------------------+---------------------+----------------------------+ | id | created_time | created_at | unix_timestamp(created_at) | +----+---------------------+---------------------+----------------------------+ | 1 | 2020-12-09 08:00:00 | 2020-12-09 00:00:00 | 1607472000 | | 2 | 2020-12-09 08:00:00 | 2020-12-09 08:00:00 | 1607500800 | +----+---------------------+---------------------+----------------------------+ 2 rows in set (0.18 sec) Because
The above is the details of why MySQL timestamp can ignore the time zone issue. For more information about MySQL timestamp ignoring the time zone, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Using HTML web page examples to explain the meaning of the head area code
>>: Docker uses the nsenter tool to enter the container
Problem description: structure: test has two fiel...
HTML is made up of tags and attributes, which are...
This article shares the shell script of mysql5.6....
1. Download: http://www.oracle.com/technetwork/ja...
When the submenu of the navigation bar is generat...
First, let’s take a look at the picture: Today we...
1. Color matching effect preview As shown in the ...
Table of contents 1. Timer monitoring 2. Event mo...
The key is that the local server does not have wr...
Table of contents Preface Component Introduction ...
Stored Functions What is a stored function: It en...
This article example shares the specific implemen...
1. Introduction to VMware vSphere VMware vSphere ...
The complete syntax of the SELECT statement is: (...
Table of contents Preface 1.insert ignore into 2....