由于主键错误,从站无法正常工作,如下所示:
Last_SQL_Errno: 1062
Last_SQL_Error: Error 'Duplicate entry '550696860' for key 'PRIMARY'' on query.
Default database: 'vserv'.
Query:
'INSERT INTO ox_data_intermediate_ad
(date_time, ad_id, zone_id, clicks, impressions,
requests, operation_interval, operation_interval_id,
interval_start, interval_end, creative_id, updated)
SELECT
date_time, ad_id, zone_id, SUM(clicks) AS clicks,
SUM(impressions) AS impressions, SUM(requests) AS requests,
5 AS operation_interval, 1871 AS operation_interval_id,
'2012-05-26 11:55:00' AS interval_start,
'2012-05-26 11:59:59' AS interval_end,
0 AS creative_id, '2012-05-26 12:04:01' AS updated
FROM
(
SELECT
interval_start AS date_time, creative_id AS ad_id, zone_id AS zone_id,
count AS clicks, 0 AS impressions, 0 AS requests
FROM
ox_data_bkt_c
WHERE
interval_start >= '2012-05-26 11:55:00'
AN
提到的查询不会尝试插入自动递增的列 data_intermediate_ad_id
。它期望 mysql 自动添加下一个 ID。查看slave的时候发现有一条主键550696860的记录。
Master 是 5.0,slave 是 5.5.24
第二个版本为 5.5.21 的奴隶工作正常。这是与 5.5.24 版本相关的错误吗?
有问题的查询如下:
INSERT INTO
ox_data_intermediate_ad
(date_time, ad_id, zone_id, clicks, impressions, requests, operation_interval, operation_interval_id, interval_start, interval_end, creative_id, updated)
SELECT
date_time, ad_id, zone_id, SUM(clicks) AS clicks, SUM(impressions) AS impressions, SUM(requests) AS requests, 5 AS operation_interval, 1591 AS operation_interval_id, '2012-05-25 12:35:00' AS interval_start, '2012-05-25 12:39:59' AS interval_end, 0 AS creative_id, '2012-05-25 12:43:01' AS updated
FROM
(
SELECT
interval_start AS date_time, creative_id AS ad_id, zone_id AS zone_id, count AS clicks, 0 AS impressions, 0 AS requests
FROM
ox_data_bkt_c
WHERE
interval_start >= '2012-05-25 12:35:00'
AND
interval_start <= '2012-05-25 12:39:59' UNION ALL
SELECT
interval_start AS date_time, creative_id AS ad_id, zone_id AS zone_id, 0 AS clicks, count AS impressions, 0 AS requests
FROM
ox_data_bkt_m
WHERE
interval_start >= '2012-05-25 12:35:00'
AND
interval_start <= '2012-05-25 12:39:59' UNION ALL
SELECT
interval_start AS date_time, creative_id AS ad_id, zone_id AS zone_id, 0 AS clicks, 0 AS impressions, count AS requests
FROM
ox_data_bkt_r
WHERE
interval_start >= '2012-05-25 12:35:00'
AND
interval_start <= '2012-05-25 12:39:59'
) AS virtual_table
GROUP BY
date_time, ad_id, zone_id
我想知道为什么奴隶对insert into ... select
声明有疑问。
永远不会发生重复键错误。当它发生时,那么可能
永远不要写信给奴隶。建议在 Slave 上设置 readonly=ON。这将(主要)防止意外写入。但是,用户“root”(或任何超级用户)将绕过只读检查。
正如 Aaron 提到的,percona.com 有一个工具可以检查主从之间的一致性。他们有另一个同步它们的工具。