[HTTPS://大巴.stack Exchange.com/questions/20217/MySQL-set-UTC-time-阿斯-default-timestamp]
如果删除,请引用以上链接中的所有答案:
要与@ypercube的注释(CURRENT_TIMESTAMP存储为UTC但作为当前时区检索)一起使用,可以使用--default_time_zone选项进行检索来影响服务器的时区设置。 这使您的检索始终使用UTC。
默认情况下,选项为“ SYSTEM”,这是设置系统时区的方式(可能为UTC,也可能不是UTC!):
mysql> SELECT @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM | SYSTEM |
+--------------------+---------------------+
1 row in set (0.00 sec)
mysql> SELECT CURRENT_TIMESTAMP();
+---------------------+
| CURRENT_TIMESTAMP() |
+---------------------+
| 2012-09-25 16:28:45 |
+---------------------+
1 row in set (0.00 sec)
您可以动态设置:
mysql> SET @@session.time_zone='+00:00';
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM | +00:00 |
+--------------------+---------------------+
1 row in set (0.00 sec)
或永久存在于您的my.cnf中:
[mysqld]
**other variables**
default_time_zone='+00:00'
重新启动服务器,您将看到更改:
mysql> SELECT @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| +00:00 | +00:00 |
+--------------------+---------------------+
1 row in set (0.00 sec)
mysql> SELECT CURRENT_TIMESTAMP();
+---------------------+
| CURRENT_TIMESTAMP() |
+---------------------+
| 2012-09-25 20:27:50 |
+---------------------+
1 row in set (0.01 sec)