mysql删除不存在行数据报错_MySQL学习笔记11复制错误处理(二)删除不存在的行的问题...

master上删除某个数据表的某一行,而该行在slave上并不存在,则slave上的复制过程会出错。

MySQL的log文件中发现如下错误信息:

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)重现问题场景。

(a)在slave上删除数据表test的某一行数据。

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上删除数据表test的该行数据。

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)

删除后再插入新的数据。

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上的数据。

mysql> select * from test;

+-------+

| name2 |

+-------+

| 002   |

| 003   |

+-------+

2 rows in set (0.00 sec)

可以看到slave中并没有发现master上新插入的行’004’。

(d)查看slave的复制状态。

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)

可以看到,出现了错误代码未1032的错误信息,删除的行不存在。

(3)解决办法。

由于导致出错的原因是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的复制(GTID_MODE = ON)时,不能使用sql_slave_skip_counter的方法来忽略错误;而是应该使用reset master重置mysql.gtid_executed数据表。

此时查看复制状态:

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)

已经恢复到正常状态了。

查看数据表的数据,也可以看到跟master中的数据完全一样了,即可以看到新增的行。

mysql> select * from test;

+-------+

| name2 |

+-------+

| 002   |

| 003   |

| 004   |

+-------+

3 rows in set (0.00 sec)

至此,删除不存在的行导致的复制错误,已经成功得到解决。

MySQL学习笔记11复制错误处理(二)删除不存在的行的问题

标签:bin   pos   connect   space   handler   relay_log   where   导致   int

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:http://www.cnblogs.com/coe2coe/p/7439370.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值