一、傳統(tǒng)binlog主從復(fù)制,跳過報錯方法
mysql> stop slave;
mysql> set global sql_slave_skip_counter = 1;
mysql> start slave;
mysql> show slave status \G
二、GTID主從復(fù)制,跳過報錯方法
mysql> stop slave; #先關(guān)閉slave復(fù)制;
mysql> change master to ...省略... #配置主從復(fù)制;
mysql> show slave status\G #查看主從狀態(tài);
發(fā)現(xiàn)報錯:
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.19.195.212
Master_User: master-slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000021
Read_Master_Log_Pos: 194
Relay_Log_File: nginx-003-relay-bin.000048
Relay_Log_Pos: 454
Relay_Master_Log_File: mysql-bin.000016
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: 1007
Last_Error: Error 'Can't create database 'code'; database exists' on query. Default database: 'code'. Query: 'create database code'
Skip_Counter: 0
Exec_Master_Log_Pos: 8769118
Relay_Log_Space: 3500
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
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: 0
Last_IO_Error:
Last_SQL_Errno: 1007
Last_SQL_Error: Error 'Can't create database 'code'; database exists' on query. Default database: 'code'. Query: 'create database code'
Replicate_Ignore_Server_Ids:
Master_Server_Id: 100
Master_UUID: fea89052-11ef-11eb-b241-00163e00a190
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp: 201022 09:31:29
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: fea89052-11ef-11eb-b241-00163e00a190:8-5617
Executed_Gtid_Set: a56c9b04-11f1-11eb-a855-00163e128853:1-11224,
fea89052-11ef-11eb-b241-00163e00a190:1-5614
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.01 sec)
可以看到 Slave_SQL_Running 為 NO,表示運行取回的二進制日志出了問題;
在 Last_Error 中也可以看到大概的報錯;(因為我之前的操作,大概可以判斷出 是因為主庫的二進制日志中有創(chuàng)建code庫的sql,而從庫上我已經(jīng)創(chuàng)建了這個庫,應(yīng)該是產(chǎn)生了沖突;)
解決方法:
1、如果清楚自己之前的操作,可以將從庫中產(chǎn)生沖突的庫刪除;
2、或者通過跳過GTID報錯的事務(wù)的方法
--- 通過 Last_SQL_Errno 報錯編號查詢具體的報錯事務(wù)
mysql> select * from performance_schema.replication_applier_status_by_worker where LAST_ERROR_NUMBER=1007\G
*************************** 1. row ***************************
CHANNEL_NAME:
WORKER_ID: 0
THREAD_ID: NULL
SERVICE_STATE: OFF
LAST_SEEN_TRANSACTION: fea89052-11ef-11eb-b241-00163e00a190:5615
LAST_ERROR_NUMBER: 1007
LAST_ERROR_MESSAGE: Error 'Can't create database 'code'; database exists' on query. Default database: 'code'. Query: 'create database code'
LAST_ERROR_TIMESTAMP: 2020-10-22 09:31:29
1 row in set (0.00 sec)
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
--- 跳過查找到報錯的事務(wù)(LAST_SEEN_TRANSACTION 的值)
mysql> set @@session.gtid_next='fea89052-11ef-11eb-b241-00163e00a190:5615';
Query OK, 0 rows affected (0.00 sec)
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
--- 提交一個空的事務(wù),因為設(shè)置gtid_next后,gtid的生命周期開始了,必須通過顯性的提交一個事務(wù)來結(jié)束;
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
--- 設(shè)置回自動模式;
mysql> set @@session.gtid_next=automatic;
Query OK, 0 rows affected (0.00 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
通過以上步驟,就跳過了這次的GTID報錯的事務(wù),如果 start slave 之后還是有報錯,那么就按照此步驟繼續(xù)跳過;
經(jīng)驗豐富的話,基本不用查詢事務(wù),通過 Executed_Gtid_Set 就可以判斷出報錯的事務(wù)是 fea89052-11ef-11eb-b241-00163e00a190:5615 了;因為執(zhí)行事務(wù),到 fea89052-11ef-11eb-b241-00163e00a190:1-5614 的時候報錯了,應(yīng)該可以判斷是 5615事務(wù)出現(xiàn)的錯誤;
以上就是mysql 主從復(fù)制如何跳過報錯的詳細內(nèi)容,更多關(guān)于MySQL 跳過報錯的資料請關(guān)注腳本之家其它相關(guān)文章!
您可能感興趣的文章:- MySQL中主從復(fù)制重復(fù)鍵問題修復(fù)方法
- MySql主從復(fù)制機制全面解析
- Mysql主從復(fù)制與讀寫分離圖文詳解
- MYSQL數(shù)據(jù)庫GTID實現(xiàn)主從復(fù)制實現(xiàn)(超級方便)
- MySql主從復(fù)制實現(xiàn)原理及配置
- MySQL主從復(fù)制原理以及需要注意的地方
- mysql主從復(fù)制配置過程
- 全面解讀MySQL主從復(fù)制,從原理到安裝配置
- 關(guān)于MySQL主從復(fù)制的幾種復(fù)制方式總結(jié)
- MySQL主從復(fù)制斷開的常用修復(fù)方法