当使用相同数据更新行时,我会在我们的(测试)Galera 集群上触发死锁。
INSERT INTO test (id, val) VALUES (1, 42), (2, 47);
-- Query OK, 2 rows affected (0.01 sec)
-- Records: 2 Duplicates: 0 Warnings: 0
将一个值更新为不同的值不会导致错误:
UPDATE test SET val=43 WHERE id=1;
-- Query OK, 1 row affected (0.00 sec)
-- Rows matched: 1 Changed: 1 Warnings: 0
当您将其设置为相同的值时:
UPDATE test SET val=47 WHERE id=2;
-- ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction
这似乎是一种被错误传达的警告(来自/var/log/mysql
):
140106 13:52:04 [Warning] WSREP: SQL statement was ineffective, THD: 12, buf: 103
QUERY: UPDATE test SET val=47 WHERE id=2
=> Skipping replication
140106 13:52:04 [Warning] WSREP: SQL statement was ineffective, THD: 12, buf: 103
QUERY: UPDATE test SET val=47 WHERE id=2
=> Skipping replication
注意:表格创建如下
CREATE TABLE IF NOT EXISTS `test` (
`id` int(3) NOT NULL PRIMARY KEY,
`val` int(3) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf-8;
答案1
如果服务器上的二进制日志格式为“STATEMENT”(通过 SELECT @@binlog_format; 检查),则应使用 --binlog-format=row 重新启动服务器,然后重试查询。通常这可以解决您的问题!