MySQLマスタースレーブまたはマスターメインレポート1032エラーを解決します



Solve Mysql Master Slave



1032エラーの主な原因は、メインライブラリの更新または削除されたレコードがスレーブライブラリに存在しないことです。
このタイプのエラーに対処するための2つの一般的な考え方があります。
1.エラー実行ステートメントを直接スキップします
2、間違った実行ステートメントを見つけ、ライブラリからデータを修正します
最初の解決策には、マスタースレーブの不整合の隠れた危険性があり(削除ステートメントはスキップできます)、2番目の解決策は問題を根本的に解決することです。

ステートメントスキップ操作方法は次のとおりです。

1032エラーメッセージは次のとおりです。



Replicate_Wild_Ignore_Table: Last_Errno: 1032 Last_Error: Could not execute Update_rows event on table test.test Can't find record in 'test', Error_code: 1032 handler error HA_ERR_KEY_NOT_FOUND the event's master log mysql1-bin.000001, end_log_pos 2579 Skip_Counter: 0

-従来のモード

mysql> stop slave # indicates skip one step error, the following numbers are variable, (or N events, one by one) mysql> set global sql_slave_skip_counter =1 mysql> start slave Then use mysql> show slave status/G to view: mysql> show slave status/G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.20 Master_User: rep1 Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql1-bin.000001 Read_Master_Log_Pos: 2610 Relay_Log_File: cndba-relay-bin.000005 Relay_Log_Pos: 321 Relay_Master_Log_File: mysql1-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: test # Skip all 1032 errors Change the my.cnf file and add it under Replication settings: slave-skip-errors = 1032 And restart the database, then start salve. Note: It is not recommended because you want to restart the database unless there are too many error events.

-GTIDモード

mysql> stop slave Find the Retrieved_Gtid_Set: 7800a22c-95ae-11e4-983d-080027de205a:12 by show slave status/G mysql> set GTID_NEXT='7800a22c-95ae-11e4-983d-080027de205a:12' mysql> begincommit mysql> set GTID_NEXT='AUTOMATIC' mysql> start slave

1032シーンをシミュレートします。

メインライブラリ作成テーブル

mysql> create table test(id int PRIMARY KEY ,name varchar(32)) Query OK, 0 rows affected (0.06 sec) Modify the parameter sql_log_bin to make the main library operation not sync to the slave library mysql> set sql_log_bin=0 Query OK, 0 rows affected (0.00 sec) mysql> insert into test values (1,'aa') Query OK, 1 row affected (0.02 sec) mysql> insert into test values (2,'bb') Query OK, 1 row affected (0.01 sec) mysql> insert into test values (3,'dd') Query OK, 1 row affected (0.00 sec) Modify the parameter sql_log_bin to synchronize the main library operation statement to the slave library. mysql> set sql_log_bin=1 Query OK, 0 rows affected (0.00 sec) mysql> insert into test values (4,'cc') Query OK, 1 row affected (0.08 sec) mysql> select * from test +----+------+ | id | name | +----+------+ | 1 | aa | | 2 | bb | | 3 | dd | | 4 | cc | +----+------+ 4 rows in set (0.00 sec)

ライブラリからのデータ同期の表示

You can see that only one data is synchronized from the library data. mysql> select * from test +----+------+ | id | name | +----+------+ | 4 | cc | +----+------+ 1 row in set (0.00 sec)

メインライブラリの更新テーブルテストで

mysql> update test set name = 'abc' where id=1 Query OK, 1 row affected (0.07 sec) Rows matched: 1 Changed: 1 Warnings: 0 At this point insert a piece of data: mysql> insert into test values (5,'dd') Query OK, 1 row affected (0.01 sec)

スタンバイデータベースでマスタースレーブステータスを表示する

1032エラーが見つかりました。このエラーの理由は、ライブラリにid = 1データがないため、メインライブラリが更新され、ライブラリに変更する対応するデータがないためです。

mysql> show slave status/G ...... Last_Errno: 1032 Last_Error: Could not execute Update_rows event on table test.test Can't find record in 'test', Error_code: 1032 handler error HA_ERR_KEY_NOT_FOUND the event's master log mysql1-bin.000001, end_log_pos 2037 Skip_Counter: 0 Exec_Master_Log_Pos: 1792 Relay_Log_Space: 2264 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: 1032 Last_SQL_Error: Could not execute Update_rows event on table test.test Can't find record in 'test', Error_code: 1032 handler error HA_ERR_KEY_NOT_FOUND the event's master log mysql1-bin.000001, end_log_pos 2037 Replicate_Ignore_Server_Ids: Master_Server_Id: 20 ......

解決:

Find the missing data from the library according to the location of the master log and end_log_pos prompted in Last_Error Main library operation: [root@xxxxx binlog]# mysqlbinlog --no-defaults -v --base64-output=decode-rows --stop-position=2037 /data/mysql/binlog/mysql1-bin.000001 | tail -20 SET TIMESTAMP=1534626999/*!*/ BEGIN /*!*/ # at 1934 #180819 5:16:39 server id 20 end_log_pos 1984 CRC32 0x666a3738 Table_map: `test`.`test` mapped to number 220 # at 1984 #180819 5:16:39 server id 20 end_log_pos 2037 CRC32 0x74a99c1f Update_rows: table id 220 flags: STMT_END_F ### UPDATE `test`.`test` ### WHERE ### @1=1 ### @2='aa' ### SET ### @1=1 ### @2='abc' ROLLBACK /* added by mysqlbinlog */ /*!*/ SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/ DELIMITER # End of log file /*!50003 SET root@xxxxx_COMPLETION_TYPE*/ /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/ After finding it, manually convert to an insert statement Execute the following statement from the library: mysql> insert into `test`.`test` values (1,'aa') Query OK, 1 row affected (0.03 sec) Start replication mysql> start slave Query OK, 0 rows affected (0.03 sec) View the status from the library: mysql> show slave status/G ...... Slave_IO_Running: Yes Slave_SQL_Running: Yes ...... mysql> select * from test +----+------+ | id | name | +----+------+ | 1 | abc | | 4 | cc | | 5 | dd | +----+------+

以上の結果から、状態は正常であり、エラーがスレーブライブラリに渡された後に挿入されたデータから、1032エラーの修復はエラー発生後のデータに影響を与えないと結論付けることができます。