您好,登錄后才能下訂單哦!
首先需要查看mysql的當前時區,用time_zone參數
mysql> show global variables like '%zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST | ---系統時間,北京時間
| time_zone | SYSTEM | ----mysql所用的時區,這里是調用系統時區,也就是北京時間
+------------------+--------+
2 rows in set (0.17 sec)
驗證下:
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2018-11-30 17:11:55 |
+---------------------+
1 row in set (0.18 sec)
修改為utc時區
mysql> set time_zone='+0:00';
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2018-11-30 09:12:06 |
+---------------------+
1 row in set (0.18 sec)
修改為東八區
mysql> set time_zone='+8:00';
Query OK, 0 rows affected (0.24 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2018-11-30 17:21:40 |
+---------------------+
1 row in set (0.72 sec)
永久修改可以通過修改my.cnf
在 [mysqld] 之下加
default-time-zone=timezone
來修改時區。如:
default-time-zone = '+8:00'
修改完了記得記得重啟msyql
注意一定要在 [mysqld] 之下加 ,否則會出現 unknown variable 'default-time-zone=+8:00'
注意:時區這個對timestamp類型的才有影響,datetime 是沒影響的,如:
mysql> select * from uc_smallfeature_sharerecords(時間戳是timestamp類型);
+------+---------------------+-------------+----------+--------+----------+
| id | create_time | destination | platform | userid | username |
+------+---------------------+-------------+----------+--------+----------+
| 3425 | 2018-12-25 19:42:51 | 123213 | 123 | 123 | 123 |
+------+---------------------+-------------+----------+--------+----------+
mysql> select * from uc_push_token(時間戳是datetime類型);
+---------+-----------+-------+---------------------+---------------------+
| user_id | push_type | token | create_time | update_time |
+---------+-----------+-------+---------------------+---------------------+
| 1 | 0 | | 2018-12-25 19:40:49 | 2018-12-25 19:40:49 |
+---------+-----------+-------+---------------------+---------------------+
mysql> show global variables like '%zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | UTC |
| time_zone | +08:00 |
+------------------+--------+
2 rows in set (0.00 sec)
mysql> set global time_zone='+0:00';
Query OK, 0 rows affected (0.00 sec)
重連查詢:
mysql> select * from uc_smallfeature_sharerecords;(timestamp類型的變了)
+------+---------------------+-------------+----------+--------+----------+
| id | create_time | destination | platform | userid | username |
+------+---------------------+-------------+----------+--------+----------+
| 3425 | 2018-12-25 11:42:51 | 123213 | 123 | 123 | 123 |
+------+---------------------+-------------+----------+--------+----------+
1 row in set (0.00 sec)
mysql> select * from uc_push_token;(datetime類型的不會變)
+---------+-----------+-------+---------------------+---------------------+
| user_id | push_type | token | create_time | update_time |
+---------+-----------+-------+---------------------+---------------------+
| 1 | 0 | | 2018-12-25 19:40:49 | 2018-12-25 19:40:49 |
+---------+-----------+-------+---------------------+---------------------+
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。