环境:
测试case:
① 1062 Error: Could not execute...event on table db.x; Duplicate entry'xx' for key'PRIMARY', Error_code: 1062;
CREATE TABLE `x` ( `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 Table record on master and slave: M: select * from x; +----+ | id | +----+ | 2 | | 3 | +----+ 2 rows in set (0.01 sec) S: select * from x; +----+ | id | +----+ | 1 | | 2 | | 3 | +----+ 3 rows in set (0.00 sec)
show variables like'slave_exec_mode'; +-----------------+--------+ | Variable_name | Value | +-----------------+--------+ | slave_exec_mode | STRICT | +-----------------+--------+ 1 row in set (0.00 sec)
show variables like'binlog_format';
+---------------+-------+ | Variable_name | Value | +---------------+-------+ | binlog_format | ROW | +---------------+-------+ 1 row in set (0.00 sec)
insert into x values(1),(4),(5); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0
Last_SQL_Errno: 1062 Last_SQL_Error: Could not execute Write_rows event on table dba_test.x; Duplicate entry '1' for key'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin-3306.000006, end_log_pos 7124
show binlog events in'mysql-bin-3306.000006' from 6950; +-----------------------+------+------------+----- ------+-------------+----------------------------- ----+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +-----------------------+------+------------+----- ------+-------------+----------------------------- ----+ | mysql-bin-3306.000006 | 6950 | Query | 169 | 7026 | BEGIN | | mysql-bin-3306.000006 | 7026 | Table_map | 169 | 7074 | table_id: 707 (dba_test.x) | | mysql-bin-3306.000006 | 7074 | Write_rows | 169 | 7124 | table_id: 707 flags: STMT_END_F | | mysql-bin-3306.000006 | 7124 | Xid | 169 | 7155 | COMMIT/* xid=74803 */| +-----------------------+------+------------+----- ------+-------------+----------------------------- ----+ 4 rows in set (0.00 sec)
1: skip_slavesql_slave_skip_counter
stop slave;
Query OK, 0 rows affected (0.00 sec) set global sql_slave_skip_counter=[1-4]; Query OK, 0 rows affected (0.00 sec) start slave; Query OK, 0 rows affected (0.00 sec)
2: Specify slave-skip-errors=1062 in the configuration file (restart required)
sql_slave_skip_counter:该参数不支持GTID模式的复制,类似于slave-skip-errors,会自动跳过出错的event而非事务
slave-skip-errors:在配置文件中设置 slave-skip-errors=1062,1032或者直接设置 slave-skip-errors= all,需要重启服务,并且在遇到相对应的错误时,从节点会自动跳过整个事务并且不会记录任何错误信息。
slave_exec_mode='IDEMPOTENT'只支持row模式的binlog,不支持statement或者mixed模式的binlog
slave_exec_mode
set global slave_exec_mode='IDEMPOTENT'; Query OK, 0 rows affected (0.00 sec) stop slave;
Query OK, 0 rows affected (0.00 sec) start slave; Query OK, 0 rows affected (0.00 sec)
insert into x values(1),(4),(5);
M: select * from x; +----+ | id | +----+ | 1 | | 2 | | 3 | | 4 | | 5 | +----+ 5 rows in set (0.00 sec) S: select * from x; +----+ | id | +----+ | 1 | | 2 | | 3 | | 4 | | 5 | +----+ 5 rows in set (0.01 sec)
② Error 1032: Could not execute...event on table db.x; Can't find record in'x', Error_code: 1032;
CREATE TABLE `x` ( `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 Table record on master and slave: M: select * from x; +----+ | id | +----+ | 1 | | 2 | | 3 | +----+ 3 rows in set (0.00 sec) S: select * from x; +----+ | id | +----+ | 1 | | 3 | +----+ 2 rows in set (0.00 sec)
show variables like'slave_exec_mode'; +-----------------+--------+ | Variable_name | Value | +-----------------+--------+ | slave_exec_mode | STRICT | +-----------------+--------+ 1 row in set (0.00 sec) The binlog mode on M is: show variables like'binlog_format';
+---------------+-------+ | Variable_name | Value | +---------------+-------+ | binlog_format | ROW | +---------------+-------+ 1 row in set (0.00 sec)
Execute on M: BEGIN; INSERT INTO x SELECT 4; DELETE FROM x WHERE id = 2; INSERT INTO x SELECT 5; COMMIT; Because there is no record with id=2 from the above, at this time, the copy of from has reported an error of 1032: Last_SQL_Errno: 1032 Last_SQL_Error: Could not execute Delete_rows event on table dba_test.x; Can't find record in'x', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin-3306.000006, end_log_pos 12102
set global slave_exec_mode='IDEMPOTENT'; Query OK, 0 rows affected (0.00 sec) stop slave;
Query OK, 0 rows affected (0.00 sec) start slave; Query OK, 0 rows affected (0.00 sec) Perform the same operation on M: BEGIN; INSERT INTO x SELECT 4; DELETE FROM x WHERE id = 2; INSERT INTO x SELECT 5; COMMIT;
总结
文章来源地址https://www.toymoban.com/news/detail-750823.html
文章来源:https://www.toymoban.com/news/detail-750823.html
到了这里,关于MySQL中的slave_exec_mode 参数详解(MySQL从节点复制错误处理时,sql_slave_skip_counter VS slave-skip-errors VS slave_exec_mode)(译)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!