【Mysql】修改mysql时区
首先需要查看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 |
+---------+-----------+-------+---------------------+---------------------+
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341