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
When we are writing a page, we often encounter a ...
Project Documentation Directory Div+CSS Naming Sta...
XML Schema is an XML-based alternative to DTD. XM...
Preface This article contains 1. Several major co...
I used Vue.js to make a nine-grid image display m...
Let’s take a look at the panoramic view effect: D...
How to modify the mysql table partitioning progra...
As shown below: Mainly execute authorization comm...
Demand: This demand is an urgent need! In a subwa...
When using nginx as a reverse proxy, you can simp...
Table of contents Variable Scope The concept of c...
Mac latest version of MySQL 8.0.22 password recov...
1.MySQL replication concept It means transferring...
Scenario: An inspection document has n inspection...
Table of contents 1. Introduction 2. Self-increme...