MySQL主從復制中的問題(Coordinator stopped beacause there were errors in the workers......)


1、show slave status \G 顯示如下報錯信息:

Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction ...

 

 

 

2、根據提示信息定位報錯位置

情況一:"Delete_rows"

select * from performance_schema.replication_applier_status_by_worker \G
Last_SQL_Error: Could not execute Delete_rows
event on table xxx ,Can't find record in xxx

 

 

 原因:在master上刪除一條記錄,而slave上找不到。

解決方法: 由於master要刪除一條記錄,而slave上找不到故報錯,這種情況主上都將其刪除了,那么從機可以直接跳過。

stop slave;
set global sql_slave_skip_counter=1;
start slave;

如上命令若報錯:
ERROR 1858 (HY000): sql_slave_skip_counter can not be set when the server is running with @@GLOBAL.GTID_MODE = ON. Instead, for each transaction that you want to skip, generate an empty transaction with the same GTID as the transaction
或者可以換用如下命令:
STOP SLAVE;
SET @@SESSION.GTID_NEXT= 'f396f867-d755-11xxx85-005xxxxxb5a:264261655'    --在session里設置gtid_next,即跳過這個GTID BEGIN; COMMIT; --設置空事物 SET SESSION GTID_NEXT = AUTOMATIC; -- 恢復GTID START SLAVE;xxxx

 

情況二:"Duplicate "

Last_SQL_Error: Could not execute Write_rows event on table xxx;
Duplicate entry 'xxx' for key 'PRIMARY',

原因:在slave已經有該記錄,又在master上插入了同一條記錄

解決方法:在從庫上刪除該記錄,或者跳過該記錄。然后在master上和slave上再分別確認一下。

 

情況三:"Update_rows"     (還未碰到 待驗證)

Last_SQL_Error: Could not execute Update_rows event on table xxx;
Can't find record in 'xxx',

參考原因:在master上更新一條記錄,而slave上找不到,丟失了數據。

參考方法:在master上,用mysqlbinlog 分析下出錯的binlog日志在干什么。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/usr/local/mysql/bin/mysqlbinlog --no-defaults -v -v --base64-output=DECODE-ROWS mysql-bin.000010 | grep -A '10' 794
 
#120302 12:08:36 server id 22 end_log_pos 794 Update_rows: table id 33 flags: STMT_END_F
### UPDATE hcy.t1
### WHERE
### @1=2 /* INT meta=0 nullable=0 is_null=0 */
### @2='bbc' /* STRING(4) meta=65028 nullable=1 is_null=0 */
### SET
### @1=2 /* INT meta=0 nullable=0 is_null=0 */
### @2='BTV' /* STRING(4) meta=65028 nullable=1 is_null=0 */
# at 794
#120302 12:08:36 server id 22 end_log_pos 821 Xid = 60
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;

 

在slave上,查找下更新后的那條記錄,應該是不存在的。

mysql> select * from t1 where id=2;
Empty set (0.00 sec)

然后再到master查看

1
2
3
4
5
6
7
mysql> select * from t1 where id=2;
+----+------+
| id | name |
+----+------+
| 2 | BTV |
+----+------+
1 row in set (0.00 sec)

 

把丟失的數據在slave上填補,然后跳過報錯即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
mysql> insert into t1 values (2,'BTV');
Query OK, 1 row affected (0.00 sec)
 
mysql> select * from t1 where id=2;
+----+------+
| id | name |
+----+------+
| 2 | BTV |
+----+------+
1 row in set (0.00 sec)
 
mysql> stop slave ;set global sql_slave_skip_counter=1;start slave;
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
 
mysql> show slave status\G;
……
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
……

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM