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

MySQL replication uses unix_timestamp for timestamp type

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

我有两个 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

我的sqlbinlog上的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 子句上使用时间戳值时,没有结果。

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

你确定这个binlog来自这个SQLDELETE FROM tosa.liv_low WHERE BOSA_ID = 'BE41008-44500244'

我做了一个简单的测试:

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

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

  3. 删除它delete from a where id = 1

binary log里的还是delete from a where id = 1

在5.6.21-70.1-log上测试,binlog格式为MIXED(反正应该无所谓)