MySQL GTID复制错误处理之跳过错误

某Slave报错信息:

mysql> show slave status\G;
mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.206.140
Master_User: u_repl
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: localhost-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker failed executing transaction '9e2c7c0f-0908-11e7-8230-000c29ab7544:1' at master log mysql-bin., end_log_pos . See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker failed executing transaction '9e2c7c0f-0908-11e7-8230-000c29ab7544:1' at master log mysql-bin., end_log_pos . See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 9e2c7c0f--11e7--000c29ab7544
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp: ::
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 9e2c7c0f--11e7--000c29ab7544:-
Executed_Gtid_Set: 347cbac6--11e7-b957-000c2981a46e:,
c59a2526-08fd-11e7-a5c7-000c296f2953:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec) ERROR:
No query specified

GTID的复制对于错误信息的可读性不是很好,但可以通过错误代码(1007)从监控表replication_applier_status_by_worker查看:

mysql> select * from performance_schema.replication_applier_status_by_worker where LAST_ERROR_NUMBER=\G
mysql> select * from performance_schema.replication_applier_status_by_worker where LAST_ERROR_NUMBER=\G
*************************** . row ***************************
CHANNEL_NAME:
WORKER_ID:
THREAD_ID: NULL
SERVICE_STATE: OFF
LAST_SEEN_TRANSACTION: 9e2c7c0f--11e7--000c29ab7544:
LAST_ERROR_NUMBER:
LAST_ERROR_MESSAGE: Worker failed executing transaction '9e2c7c0f-0908-11e7-8230-000c29ab7544:1' at master log mysql-bin., end_log_pos ; Error 'Can't create database 'mydb'; database exists' on query. Default database: 'mydb'. Query: 'create database mydb'
LAST_ERROR_TIMESTAMP: -- ::
row in set (0.00 sec)

使用GTID跳过错误的方法:找到错误的GTID跳过(通过Exec_Master_Log_Pos去binlog里找GTID,或则通过上面监控表replication_applier_status_by_worker找到GTID,也可以通过Executed_Gtid_Set算出GTID),这里使用监控表来找到错误的GTID。找到GTID之后,跳过错误的步骤

mysql> stop slave; #停止同步
Query OK, rows affected (0.02 sec) mysql> set @@session.gtid_next='9e2c7c0f-0908-11e7-8230-000c29ab7544:1'; #跳过错误的GTID
Query OK, rows affected (0.00 sec) mysql> begin; #提交一个空事务,因为设置gtid_next后,gtid的生命周期就开始了,必须通过显性的提交一个事务来结束,否则报错:ERROR (HY000): @@SESSION.GTID_NEXT cannot be changed by a client that owns a
Query OK, rows affected (0.00 sec) mysql> commit;
Query OK, rows affected (0.01 sec) mysql> set @@session.gtid_next=automatic; #设置回自动模式
Query OK, rows affected (0.00 sec) mysql> start slave;
Query OK, rows affected (0.02 sec)

再次确认slave同步状况

mysql> show slave status\G;
mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.206.140
Master_User: u_repl
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: localhost-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 9e2c7c0f--11e7--000c29ab7544
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 9e2c7c0f--11e7--000c29ab7544:-
Executed_Gtid_Set: 347cbac6--11e7-b957-000c2981a46e:,
9e2c7c0f--11e7--000c29ab7544:-,
c59a2526-08fd-11e7-a5c7-000c296f2953:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec) ERROR:
No query specified

打完收工

本文地址:http://www.cnblogs.com/ajiangg/p/6558714.html

上一篇:java线程基础知识----java线程模型


下一篇:3DES加解密类