How to set MySQL to use GMT in Windows and Linux

2019-02-02 22:57发布

I'm just trying to get MySQL to store time in GMT...

I've read the documentation here: http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html

It says to set: default-time-zone='timezone' in an option file.

However, I've googled for several different terms and cannot find possible values "timezone" is supposed to be. I also don't know where in my.ini (and in Linux, my.cnf) to put this directive. Below [msyqld] ?

标签: mysql date time
6条回答
贼婆χ
2楼-- · 2019-02-02 23:23

The MySQL Timezone table is not loaded by default, which might be why you're experiencing difficulties. You need to load the timezone table and then set your timezone using the instructions above.

查看更多
相关推荐>>
3楼-- · 2019-02-02 23:32

Go to [mysqld] section of your my.ini file and under that section enter this line

default-time-zone = '+00:00'

'+00:00' indicates the offset from GMT which in your case will be 0. Please note the '+' sign in the string.

You don't need to install any timezone tables for your problem. After restarting the server, your server will operate in the UTC timezone and hence NOW() will give you the time in GMT.

By default, MySQL is set to your SYSTEM timezone ie. your server timezone is same as your system timezone. So you could also change your system time zone to solve your problem, though this is not recommendable.

查看更多
欢心
4楼-- · 2019-02-02 23:35

Yes, that's a server option for mysqld, and so should be put in the [mysqld] section.

Also, regarding values, see The Definitive Guide to MySQL 5

查看更多
forever°为你锁心
5楼-- · 2019-02-02 23:41

Just to save a few clicks, the list of zone names is shown like this:

select name from mysql.time_zone_name;

Beware of setting a fixed-offset zone such as 'GMT' or '+00:00' since it will not alter to match local time / DST etc. If you want it to follow local time, set the zone to 'Europe/London' instead. If you don't want that I'd go for UTC over GMT anyway.

查看更多
三岁会撩人
6楼-- · 2019-02-02 23:44

I use this for GMT+2: SET GLOBAL time_zone = '+02:00';

查看更多
Explosion°爆炸
7楼-- · 2019-02-02 23:47

Screw this... DATETIME, although much easier on the eye when viewing tables, isn't worth this nightmare.

I'm just going to use TIMESTAMP.

查看更多
登录 后发表回答