简体   繁体   中英

Mysql different time on different servers

I have 2 server on which they have different time, I'd like to know how to make they both have the same time. Here's my time difference:

SELECT @@global.time_zone, @@session.time_zone; -- this is my correct time
SELECT now()  

it returns the following:

    SELECT @@global.time_zone, @@session.time_zone;
    SELECT now();

+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM             | SYSTEM              |
+--------------------+---------------------+
1 row in set

+---------------------+
| now()               |
+---------------------+
| 2015-12-15 07:04:15 |
+---------------------+
1 row in set

and on the other server i got this (incorrect time or different to the other):

    SELECT @@global.time_zone, @@session.time_zone;
SELECT now();
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM             | SYSTEM              |
+--------------------+---------------------+
1 row in set

+---------------------+
| now()               |
+---------------------+
| 2015-12-15 13:02:05 |
+---------------------+
1 row in set

Is that possible, considering that correct server is physically on Peru and the other is on Spain?. I have Linux on both server and i want to know exactly what is suppose to modify on my config(if any). I also have access to my servers by ssh, but I'm interested to make it right on my second server.

I dont think that clock may be runaway that much, so system timezone must be different on servers, plus there's about 2 minute difference, if it's not due to commands being run not at the same moment then one or both of the servers probably does not have ntpd running and correcting system clock.

If its only the system timezone - then change it, or if you can change only the mysql's one.

If you cannot control even that - set session timezone, anyway this does not change the timestamps stored, only how they are displayed and parsed.

See cheatsheet here: Should MySQL have its timezone set to UTC?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM