mysql删除不存在行数据报错_MySQL学习笔记11复制错误处理(二)删除不存在的行的问题...
(1)問題情況
在master上刪除某個數(shù)據(jù)表的某一行,而該行在slave上并不存在,則slave上的復(fù)制過程會出錯。
MySQL的log文件中發(fā)現(xiàn)如下錯誤信息:
2017-08-15T04:52:19.529509Z 13 [ERROR] Slave SQL for channel ‘‘: Could not execute Delete_rows event on table test.test; Can‘t find record in ‘test‘, Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event‘s master log mysql-bin.000007, end_log_pos 1958, Error_code: 1032
2017-08-15T04:52:19.529575Z 13 [Warning] Slave: Can‘t find record in ‘test‘ Error_code: 1032
2017-08-15T04:52:19.529588Z 13 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log ‘mysql-bin.000007‘ position 1732
(2)重現(xiàn)問題場景。
(a)在slave上刪除數(shù)據(jù)表test的某一行數(shù)據(jù)。
mysql> delete from test where name2=‘001‘;
Query OK, 1 row affected (0.07 sec)
mysql> select * from test;
+-------+
| name2 |
+-------+
| 002 ??|
| 003 ??|
+-------+
2 rows in set (0.00 sec)
(b)在master上刪除數(shù)據(jù)表test的該行數(shù)據(jù)。
mysql> select * from test;
+-------+
| name2 |
+-------+
| 001 ??|
| 002 ??|
| 003 ??|
+-------+
3 rows in set (0.00 sec)
mysql> delete from test where name2=‘001‘;
Query OK, 1 row affected (0.02 sec)
mysql> select * from test;
+-------+
| name2 |
+-------+
| 002 ??|
| 003 ??|
+-------+
2 rows in set (0.00 sec)
刪除后再插入新的數(shù)據(jù)。
mysql> insert into test (name2) values( ‘004‘ );
Query OK, 1 row affected (0.02 sec)
mysql> select * from test;
+-------+
| name2 |
+-------+
| 002 ??|
| 003 ??|
| 004 ??|
+-------+
3 rows in set (0.00 sec)
(c)查看slave上的數(shù)據(jù)。
mysql> select * from test;
+-------+
| name2 |
+-------+
| 002 ??|
| 003 ??|
+-------+
2 rows in set (0.00 sec)
可以看到slave中并沒有發(fā)現(xiàn)master上新插入的行’004’。
(d)查看slave的復(fù)制狀態(tài)。
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: mysql101.coe2coe.me
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 2246
Relay_Log_File: mysql103-relay-bin.000017
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000007
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: mysql.%,information_schema.%,performance_schema.%,sys.%
Last_Errno: 1032
Last_Error: Could not execute Delete_rows event on table test.test; Can‘t find record in ‘test‘, Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event‘s master log mysql-bin.000007, end_log_pos 1958
Skip_Counter: 0
Exec_Master_Log_Pos: 1732
Relay_Log_Space: 1835
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 Delete_rows event on table test.test; Can‘t find record in ‘test‘, Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event‘s master log mysql-bin.000007, end_log_pos 1958
Replicate_Ignore_Server_Ids:
Master_Server_Id: 101
Master_UUID: a2392929-6dfb-11e7-b294-000c29b1c101
Master_Info_File: /opt/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: 170815 12:52:19
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
可以看到,出現(xiàn)了錯誤代碼未1032的錯誤信息,刪除的行不存在。
(3)解決辦法。
由于導(dǎo)致出錯的原因是slave中不存在待刪除的行,此時可以直接忽略該錯誤。
mysql> stop slave;
Query OK, 0 rows affected (0.01 sec)
mysql> set global sql_slave_skip_counter=1;
Query OK, 0 rows affected (0.00 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
注意:在使用基于GTID的復(fù)制(GTID_MODE = ON)時,不能使用sql_slave_skip_counter的方法來忽略錯誤;而是應(yīng)該使用reset master重置mysql.gtid_executed數(shù)據(jù)表。
此時查看復(fù)制狀態(tài):
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: mysql101.coe2coe.me
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 2246
Relay_Log_File: mysql103-relay-bin.000018
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000007
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: mysql.%,information_schema.%,performance_schema.%,sys.%
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 2246
Relay_Log_Space: 1210
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: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 101
Master_UUID: a2392929-6dfb-11e7-b294-000c29b1c101
Master_Info_File: /opt/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
已經(jīng)恢復(fù)到正常狀態(tài)了。
查看數(shù)據(jù)表的數(shù)據(jù),也可以看到跟master中的數(shù)據(jù)完全一樣了,即可以看到新增的行。
mysql> select * from test;
+-------+
| name2 |
+-------+
| 002 ??|
| 003 ??|
| 004 ??|
+-------+
3 rows in set (0.00 sec)
至此,刪除不存在的行導(dǎo)致的復(fù)制錯誤,已經(jīng)成功得到解決。
總結(jié)
以上是生活随笔為你收集整理的mysql删除不存在行数据报错_MySQL学习笔记11复制错误处理(二)删除不存在的行的问题...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ps cs6磨皮插件_【PS插件】ps磨
- 下一篇: mysql 主从复制讲解_MySQL主从