【问题标题】:What is the impact of system time zone of RHEL6 server in MySQL replication?MySQL复制中RHEL6服务器的系统时区有什么影响?
【发布时间】:2015-04-29 09:54:06
【问题描述】:

我们在 EST 时区有一个主服务器,而从属服务器配置为遵循 IST 时区,但从属服务器上的 mysql 配置为 default_time_zone=EST5EDT 只是为了使两个数据库实例遵循相同的时区,但如果我执行

mysql > Select now(); 

在两台服务器上我得到相同的值,相比之下,当我使用 now() 在主实例中插入值时,它在主实例的 EST 和从属的 IST 中插入值,这导致主从数据的数据差异列。 以下是我进行的测试

 Master : (Having EST as system timezone)
 mysql> insert into test_timezone values (1,now());
  Query OK, 1 row affected (0.00 sec)

 mysql> insert into test_timezone values (2,now());
 Query OK, 1 row affected (0.00 sec)

 mysql> insert into test_timezone values (3,now());
 Query OK, 1 row affected (0.00 sec)

 mysql> select * from test_timezone;
 +------+---------------------+
 | id   | date_tz             |
 +------+---------------------+
 |    1 | 2015-02-02 02:53:46 |
 |    2 | 2015-02-02 02:53:50 |
 |    3 | 2015-02-02 02:53:54 |
 +------+---------------------+

 Slave : (Having IST as system timezone but mysql default timezone is   EST5EDT)
 mysql> select * from test_timezone;
 +------+---------------------+
 | id   | date_tz             |
 +------+---------------------+
 |    1 | 2015-02-02 13:23:46 |
 |    2 | 2015-02-02 13:23:50 |
 |    3 | 2015-02-02 13:23:54 |
 +------+---------------------+
 3 rows in set (0.00 sec)

那么在插入/更新数据时需要做些什么才能在主从设备上获得相同的时间?

【问题讨论】:

    标签: mysql timezone


    【解决方案1】:

    MySQL 依赖于系统时区。

    default-time-zone='TIMEZONE'
    

    如果 my.cnf 中没有配置这个变量,那么 MySQL 将使用系统时区来保存和显示数据。如果你想在 master 和 slave 中拥有相同的时间值,那么理想的方法是配置

    default-time-zone='TIMEZONE'
    

    master 和 slave 中的上述变量将优先于系统时区,并且您将在 master 和 slave 中具有相同的时间值。

    如果您在 MySQL 中没有找到所需的时区,请按照以下链接在 MySQL 数据库中填充时区

    https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html

    【讨论】:

      猜你喜欢
      • 2017-06-26
      • 2013-07-05
      • 2020-11-03
      • 1970-01-01
      • 2018-10-10
      • 2010-09-30
      • 2010-10-26
      • 2013-02-17
      相关资源
      最近更新 更多