MySQL 主從複製錯誤1837
MySQL5.6.37版本,某人在測試環境主庫誤操作執行刪表操作,導致主從斷開,在從庫檢視主從資訊如下:
Last_Errno: 1837
Last_Error: Worker 3 failed executing transaction '' at master log mysql-bin.013343, end_log_pos 289330740; Error 'When @@SESSION.GTID_NEXT is set to a GTID,
you must explicitly set it to a different value after a COMMIT or ROLLBACK. Please check GTID_NEXT variable manual page for detailed explanation. Current
@@SESSION.GTID_NEXT is '07fd3067-b250-11e7-a2f0-1866da9e4b15:2618462902'.' on query. Default database: 'DBNAME'. Query: 'DROP TABLE IF EXISTS TABLENAME_1,TABLENAME_2 ...
執行刪表操作怎麼可能會導致主從斷開,問後知道是透過某工具誤操作導致了刪表,並立刻停止了。
故障可能原因:
1、create table table_name as select * from table_name; 會拆分成 creat table 和 insert 兩個事務,傳到slave時,slave執行完 create table以後,沒有insert的GTID,於是報錯
2、MyISAM 儲存引擎,myisam引擎支援insert delayed語法,insert delay是非同步寫入,也就是一旦執行立即返回給客戶端成功。mysql內部處理insert delay時,會將多個執行緒的insert合併後一起執行,但是隻生成了一個GTID;於是傳到slave後,由於是myisam表,從庫的同樣只能執行第一條SQL,於是報錯
3、主庫innodb執行一個事務,只產生一個gtid,myisam不支援事務,事務的第一條執行完以後,第二個sql就沒有gtid,於是報錯
4、臨時表
5、BUG
本次故障
1、檢查對應的庫沒有MyISAM表:
select table_schema,table_name,engine from information_schema.tables where engine !='innodb' and table_schema = 'DBNAME';
2、檢查過enforce_gtid_consistency主從庫都為on,CREATE TABLE ... SELECT語句不能執行成功,並且這次故障並不涉及CREATE TABLE ... SELECT語句,故排除
3、主從儲存引擎一致
4、沒有臨時表
在主庫審計日誌檢視,執行了drop schema dbname;
20200707 12:55:20 '/* ApplicationName=DataGrip 2020.1.4 */ drop schema DBNAME'
檢視主庫 binlog :
# at 289328506
#200707 12:55:08 server id 100 end_log_pos 289328554 CRC32 0x1401e82a GTID [commit=yes]
SET @@SESSION.GTID_NEXT= '07fd3067-b250-11e7-a2f0-1866da9e4b15:2618462902'/*!*/;
# at 289328554
#200707 12:55:08 server id 100 end_log_pos 289329642 CRC32 0x0728afdf Query thread_id=2388454119 exec_time=12 error_code=0
SET TIMESTAMP=1594097708/*!*/;
SET @@session.sql_mode=270532608/*!*/;
/*!\C utf8mb4 *//*!*/;
SET @@session.character_set_client=45,@@session.collation_connection=45,@@session.collation_server=33/*!*/;
DROP TABLE IF EXISTS TABLENAME_1,TABLENAME_2,TABLENAME_3,TABLENAME_4,....../*!*/;
# at 289329642
#200707 12:55:08 server id 100 end_log_pos 289330740 CRC32 0x0d0122e4 Query thread_id=2388454119 exec_time=12 error_code=0
SET TIMESTAMP=1594097708/*!*/;
DROP TABLE IF EXISTS TABLENAME_5,TABLENAME_6,TABLENAME_7,TABLENAME_8,....../*!*/;
# at 289330740
#200707 12:55:08 server id 100 end_log_pos 289331832 CRC32 0xd8409afa Query thread_id=2388454119 exec_time=12 error_code=0
SET TIMESTAMP=1594097708/*!*/;
DROP TABLE IF EXISTS TABLENAME_9,TABLENAME_10,TABLENAME_11,TABLENAME_12,....../*!*/;
# at 289331832
#200707 12:55:08 server id 100 end_log_pos 289332298 CRC32 0xa6657cc5 Query thread_id=2388454119 exec_time=12 error_code=0
SET TIMESTAMP=1594097708/*!*/;
DROP TABLE IF EXISTS TABLENAME_13,TABLENAME_14,TABLENAME_15,TABLENAME_16,....../*!*/;
# at 289332298
#200707 12:55:20 server id 100 end_log_pos 289332346 CRC32 0x0cc19e83 GTID [commit=yes]
SET @@SESSION.GTID_NEXT= '07fd3067-b250-11e7-a2f0-1866da9e4b15:2618462903'/*!*/;
檢視從庫 binlog :
# at 19856236
#200707 12:55:08 server id 100 end_log_pos 19856284 CRC32 0x5e42595e GTID [commit=yes]
SET @@SESSION.GTID_NEXT= '07fd3067-b250-11e7-a2f0-1866da9e4b15:2618462902'/*!*/;
DROP TABLE IF EXISTS TABLENAME_1,TABLENAME_2,TABLENAME_3,TABLENAME_4,......# at 19857398
#200707 12:55:23 server id 100 end_log_pos 19857446 CRC32 0x81998bd5 GTID [commit=yes]
SET @@SESSION.GTID_NEXT= '07fd3067-b250-11e7-a2f0-1866da9e4b15:2618463065'/*!*/;
# at 19857446
#200707 12:55:23 server id 100 end_log_pos 19857509 CRC32 0x0916a5e2 Query thread_id=2388456043 exec_time=0 error_code=0
SET TIMESTAMP=1594097723/*!*/;
SET @@session.sql_mode=524288/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
BEGIN
/*!*/;
# at 19857509
#200707 12:55:23 server id 100 end_log_pos 19859435 CRC32 0x2eec3842 Rows_query
# insert into talename....
......
......
#200707 12:55:23 server id 100 end_log_pos 19860287 CRC32 0xc983ec89 Xid = 5405680966
COMMIT/*!*/;
# at 19860287
#200707 12:55:08 server id 100 end_log_pos 19861411 CRC32 0x20f2bc78 Query thread_id=2388454119 exec_time=1669 error_code=0
SET TIMESTAMP=1594097708/*!*/;
SET @@session.sql_mode=270532608/*!*/;
/*!\C utf8mb4 *//*!*/;
SET @@session.character_set_client=45,@@session.collation_connection=45,@@session.collation_server=33/*!*/;
DROP TABLE IF EXISTS TABLENAME_5,TABLENAME_6,TABLENAME_7,TABLENAME_8,....../*!*/;
# at 19861411
#200707 12:55:08 server id 100 end_log_pos 19862529 CRC32 0x35204dfe Query thread_id=2388454119 exec_time=1672 error_code=0
SET TIMESTAMP=1594097708/*!*/;
DROP TABLE IF EXISTS TABLENAME_9,TABLENAME_10,TABLENAME_11,TABLENAME_12,....../*!*/;
# at 19862529
#200707 12:55:23 server id 100 end_log_pos 19862577 CRC32 0x48b02b33 GTID [commit=yes]
SET @@SESSION.GTID_NEXT= '07fd3067-b250-11e7-a2f0-1866da9e4b15:2618463066'/*!*/;
1、因為資料庫開啟了GTID複製,每一個GTID需要與一個唯一的事務對應,"drop schema dbname;" 在從庫將刪表語句拆分成了多個語句。
2、檢視主從GTID,發現從庫GTID缺少了從'07fd3067-b250-11e7-a2f0-1866da9e4b15:2618462903' 至 '07fd3067-b250-11e7-a2f0-1866da9e4b15:2618463064'資訊
3、而且從庫在GTID為'07fd3067-b250-11e7-a2f0-1866da9e4b15:2618462902'時執行了一個DROP TABLE IF EXISTS語句後,直接進入GTID為'07fd3067-b250-11e7-a2f0-1866da9e4b15:2618463065' 執行insert into語句並COMMIT
4、COMMIT後,正常需要設定不同的@@SESSION.GTID_NEXT,但是沒有,而是再次執行DROP TABLE IF EXISTS語句。事務在GTID為'07fd3067-b250-11e7-a2f0-1866da9e4b15:2618462902'後發生了異常拆分,所以主從複製發生報錯。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28939273/viewspace-2703069/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL主從複製錯誤——列型別轉換錯誤MySql型別
- MySQL主從複製與主主複製MySql
- 解決mysql使用GTID主從複製錯誤問題MySql
- MySQL的主從複製與MySQL的主主複製MySql
- mysql5.7主從複製,主主複製MySql
- SqlServer 主從複製錯誤分析--20598SQLServer
- MySQL主從複製、半同步複製和主主複製MySql
- mysql複製--主從複製配置MySql
- MySQL 主從複製MySql
- 【MySql】主從複製MySql
- MySQL主從複製MySql
- MySQL主從複製、半同步複製和主主複製概述MySql
- MySQL主從複製_複製過濾MySql
- MySQL的主從複製、半同步複製、主主複製詳解MySql
- 配置mysql5.5主從複製、半同步複製、主主複製MySql
- MySQL主從複製原理MySql
- MySQL的主從複製MySql
- mysql--主從複製MySql
- mysql主從複製搭建MySql
- MySql 主從複製配置MySql
- MySQL主從複製配置MySql
- mysql 8.4 主從複製MySql
- MySQL 主從複製,常見的binlog錯誤及解決方法MySql
- MySQL主從複製之GTID複製MySql
- MySQL主從複製之半同步複製MySql
- MySQL主從複製之非同步複製MySql非同步
- mysql主從複製(一):一主多從MySql
- MySQL++:Liunx - MySQL 主從複製MySql
- MySQL(13)---MYSQL主從複製原理MySql
- mysql replication /mysql 主從複製原理MySql
- MySQL主從複製Last_SQL_Errno錯誤程式碼彙總說明MySqlAST
- mysql主從延遲複製MySql
- Windows Mysql主從複製部署WindowsMySql
- mysql實現主從複製MySql
- MySQL 主從複製實操MySql
- MYSQL主從複製配置(整理)MySql
- windows 下mysql主從複製WindowsMySql
- MySQL8.0主從複製MySql