MySQL复制使用unix_timestamp作为时间戳类型

时间:2015-01-07 02:30:13

标签: mysql replication unix-timestamp

MySQL Version: 5.6.21-log
OS: CentOS release 6.6 (Final)

我有两个带有replicaiton的MySQL服务器。

从属服务器获取错误 1032

Could not execute Delete_rows event on table tosa.liv_low; Can't find record in 'liv_low', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000005, end_log_pos 381675314

mysqlbinlog上的sql查询语句是

DELETE FROM `tosa`.`liv_low`
WHERE
@1='BE41008-44500244'
@2=NULL
...
@30=NULL
@31=1418180543
@32=NULL

原始查询

DELETE FROM `tosa`.`liv_low` WHERE BOSA_ID = 'BE41008-44500244'

架构的第31列是

mysql> desc tosa.liv_low;

+--------------+-------------+------+-----+-------------------+-----------------------------+
| Field        | Type        | Null | Key | Default           | Extra                       |
+--------------+-------------+------+-----+-------------------+-----------------------------+
| BOSA_ID      | varchar(30) | YES  | MUL | NULL              |                             |
| LOT_NUM      | varchar(30) | YES  |     | NULL              |                             |
...
| TEC_current2 | float(5,2)  | YES  |     | NULL              |                             |
| IN_Date      | timestamp   | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| Human        | varchar(20) | YES  |     | NULL              |                             |
+--------------+-------------+------+-----+-------------------+-----------------------------+

当我取一行时,它有' datetime'格式值。当我在WHERE子句上使用timestamp值时,没有结果。

mysql> SELECT * FROM `tosa`.`liv_low` WHERE BOSA_ID='BE41008-44500244'\G
*************************** 1. row ***************************
     BOSA_ID: BE41008-44500244
     LOT_NUM: NULL
  Kink_level: NULL
...
TEC_current2: NULL
     IN_Date: 2014-12-10 12:02:23
       Human: NULL
1 row in set (0.00 sec)

mysql> SELECT UNIX_TIMESTAMP('2014-12-10 12:02:23')\G
*************************** 1. row ***************************
UNIX_TIMESTAMP('2014-12-10 12:02:23'): 1418180543
1 row in set (0.00 sec)

mysql> SELECT * FROM `tosa`.`liv_low` WHERE IN_Date = 1418180543\G
Empty set, 1 warning (0.18 sec)

为什么MySQL复制使用' unix_timestamp'格式在时间戳类型字段?它促成了复制。

这是my.cnf的复制部分:

server-id                 = 5202

replicate-ignore-db       = cacti

log-bin                   = /home/mysql/log/mysql-bin.log
binlog-format             = ROW
binlog_cache_size         = 2M
max_binlog_size           = 1G
expire_logs_days          = 40

sync_binlog               = 1

log-slave-updates         = true
gtid-mode                 = on
;disable-gtid-unsafe-statements = true
enforce-gtid-consistency  = true
master-info-repository    = TABLE
relay-log-info-repository = TABLE
sync-master-info          = 1

1 个答案:

答案 0 :(得分:1)

您确定此binlog来自此SQL DELETE FROM tosa.liv_low WHERE BOSA_ID = 'BE41008-44500244'吗?

我做了一个简单的测试:

  1. 创建表create table a (id int(11), t timestamp)(没有主键,起初我认为这可能与没有显式主键的表有关)

  2. 插入数据insert into a (id) values (1)

  3. 将其删除delete from a where id = 1

  4. 二进制日志中的内容仍为delete from a where id = 1

    在5.6.21-70.1-log上测试,binlog格式是混合的(无论如何都应该无关紧要)