当前位置:主页 > >

mysql修改时区为utc

时间:2020-07-13 09:04:27 | 栏目: | 点击:

mysql数据库创建后,默认的时区不一定是东八区,时间取值会按照系统时区来取,如果sql语句中使用到时间的话就会有误差,所以需要修改mysql的系统时区。

1、临时解决方案
查看MySQL中time_zone的设置

show variables like “%time_zone%”;
±-----------------±-------+
| Variable_name | Value |
±-----------------±-------+
| system_time_zone | CST |
| time_zone | SYSTEM |
±-----------------±-------+
2 rows in set (0.00 sec)
查看当前数据库时间
mysql> select now();
±--------------------+
| now() |
±--------------------+
| 2019-01-31 08:53:08 |
±--------------------+
1 row in set (0.00 sec)
修改时区:
mysql> SET time_zone = ‘+0:00’; # 修改为utc,正0时区,世界统一时间
Query OK, 0 rows affected (0.00 sec)
2、永久解决方案
vim /etc/my.cnf
[mysqld]
default-time_zone = ‘+0:00’
重启mysql服务。
/etc/init.d/mysqld restart
windows下修改默认时区为UTC

修改的my.ini配置文件,mysqld下添加default-time-zone=’+00:00’


您可能感兴趣的文章:

相关文章