mysql slave复制1032错误解决方法
2013-10-23 09:54
477 查看
http://hi.baidu.com/dba_hui/item/a4b23a60ae1d6882c4d2497c
查看slave复制状态,发现SQL线程停止应用:
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.9.61
Master_User: repl
Master_Port: 3312
Connect_Retry: 60
Master_Log_File: mysql-bin.000034
Read_Master_Log_Pos: 742553356
Relay_Log_File: relay-log.000004
Relay_Log_Pos: 41832895
Relay_Master_Log_File: mysql-bin.000034
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: eoc.%,test.%,mysql.%
Replicate_Wild_Ignore_Table:
Last_Errno: 1032
Last_Error: Could not execute Delete_rows event on table eoc.eoc_course_rank; Can't find record in 'eoc_course_rank', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000034, end_log_pos 684728241
Skip_Counter: 0
Exec_Master_Log_Pos: 684727611
Relay_Log_Space: 257830925
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 eoc.eoc_course_rank; Can't find record in 'eoc_course_rank', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000034, end_log_pos 684728241
1 row in set (0.00 sec)错误日志如下:
120719 1:01:07 [ERROR] Slave SQL: Could not execute Delete_rows event on table eoc.eoc_course_rank; Can't find record in 'eoc_course_rank', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000034, end_log_pos 684728241, Error_code: 1032
120719 1:01:07 [Warning] Slave: Can't find record in 'eoc_course_rank' Error_code: 1032
120719 1:01:07 [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.000034' position 684727611从上面的情况可以看出,在slave执行从master复制过来的delete语句因为slave找不到要删除的数据,导致SQL线程报错,停止应用。也就是说master和slave上数据不一致导致的该错误。
遇到这种情况,一般都是找出错误,然后修改slave上的数据,然后启动slave,继续应用。
比如上面,要删除的数据在slave上找不到,我们就想知道是删除哪条数据呢?但是show slave status中又没有明确给出错误的语句,因此需要分析binary log来查看是哪条语句。binary log的格式是mixed,初步使用mysqlbinlog查看,发现该条语句是RBR,而不是SBR,因此需要使用--base64-output=decode-rows -v -v选项,如下:
使用binary log:
[root@awstats usr]# /usr/local/mysql5157_2/bin/mysqlbinlog --no-defaults --base64-output=decode-rows -v -v mysql-bin.000034 | grep -A 200 '684728241' > zhh.txt
或者
使用relay log:
[root@mysqldb var]# /usr/local/mysql51572/bin/mysqlbinlog --no-defaults --base64-output=decode-rows -v -v relay-log.000004 | grep -A 200 '684728241' > zhh.txt查看文件,发现以下内容:
#120719 1:01:03 server id 1 end_log_pos 684728241 Delete_rows: table id 16854 flags: STMT_END_F
### DELETE FROM eoc.eoc_course_rank
### WHERE
### @1=2 /* TINYINT meta=0 nullable=0 is_null=0 */
### @2=392 /* SHORTINT meta=0 nullable=0 is_null=0 */
### @3=574 /* INT meta=0 nullable=0 is_null=0 */
### @4='xxx' /* VARSTRING(192) meta=192 nullable=0 is_null=0 */
### @5='yyy' /* VARSTRING(1500) meta=1500 nullable=1 is_null=0 */
### @6='20111202-2df9eef5c0e33cfd643927cb1bb048fa17a40dfa.jpg' /* VARSTRING(600) meta=600 nullable=1 is_null=0 */
### @7=3 /* INT meta=0 nullable=1 is_null=0 */
### @8=256 /* INT meta=0 nullable=1 is_null=0 */
# at 684728241即出错误的语句为:
delete from eoc.eoc_course_rank
where
第一列等于2
第二列等于392
......
根据该表的主键在slave查询,发现where条件中有一个字段值不同,因此在slave上找不到要删除的数据。mysql> use eoc;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> SELECT * FROM eoc_course_rank
-> WHERE course_id=574 \G;
*************************** 1. row ***************************
rank_type: 2
rank_id: 385
course_id: 574
course_name: xxxdetail_info: yyybrief_image: 20111202-2df9eef5c0e33cfd643927cb1bb048fa17a40dfa.jpg
cp_id: 3
grade_id: 256
1 row in set (0.00 sec)ERROR:
No query specifiedmysql> UPDATE eoc_course_rank SET rank_id= 392 WHERE course_id=574;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> commit;
Query OK, 0 rows affected (0.00 sec)mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)mysql> start slave;
Query OK, 0 rows affected (0.00 sec)mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.9.61
Master_User: repl
Master_Port: 3312
Connect_Retry: 60
Master_Log_File: mysql-bin.000034
Read_Master_Log_Pos: 746616004
Relay_Log_File: relay-log.000004
Relay_Log_Pos: 95495411
Relay_Master_Log_File: mysql-bin.000034
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: eoc.%,test.%,mysql.%
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 738390127
Relay_Log_Space: 261893867
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: 4791
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.9.61
Master_User: repl
Master_Port: 3312
Connect_Retry: 60
Master_Log_File: mysql-bin.000034
Read_Master_Log_Pos: 747488636
Relay_Log_File: relay-log.000005
Relay_Log_Pos: 904068
Relay_Master_Log_File: mysql-bin.000034
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: eoc.%,test.%,mysql.%
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 747488636
Relay_Log_Space: 104594214
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:
1 row in set (0.00 sec)上面说了,产生该错误的根本原因是主从数据不一致。为什么主从数据不一致呢?
从报错的时间点分析,发现该错误数据是一个event执行后产生的,查看该event,发现有存在结果集不确定的语句。修改该event的sql,再次执行该event调用的stored procedure,状态仍然为双YES。另外有一点不明白:my.cnf中设置的binary log是mixed格式:在未修改该sql之前,该行数据binary log记录的是RBR格式;修改后记录的是SBR格式。
查看slave复制状态,发现SQL线程停止应用:
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.9.61
Master_User: repl
Master_Port: 3312
Connect_Retry: 60
Master_Log_File: mysql-bin.000034
Read_Master_Log_Pos: 742553356
Relay_Log_File: relay-log.000004
Relay_Log_Pos: 41832895
Relay_Master_Log_File: mysql-bin.000034
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: eoc.%,test.%,mysql.%
Replicate_Wild_Ignore_Table:
Last_Errno: 1032
Last_Error: Could not execute Delete_rows event on table eoc.eoc_course_rank; Can't find record in 'eoc_course_rank', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000034, end_log_pos 684728241
Skip_Counter: 0
Exec_Master_Log_Pos: 684727611
Relay_Log_Space: 257830925
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 eoc.eoc_course_rank; Can't find record in 'eoc_course_rank', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000034, end_log_pos 684728241
1 row in set (0.00 sec)错误日志如下:
120719 1:01:07 [ERROR] Slave SQL: Could not execute Delete_rows event on table eoc.eoc_course_rank; Can't find record in 'eoc_course_rank', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log mysql-bin.000034, end_log_pos 684728241, Error_code: 1032
120719 1:01:07 [Warning] Slave: Can't find record in 'eoc_course_rank' Error_code: 1032
120719 1:01:07 [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.000034' position 684727611从上面的情况可以看出,在slave执行从master复制过来的delete语句因为slave找不到要删除的数据,导致SQL线程报错,停止应用。也就是说master和slave上数据不一致导致的该错误。
遇到这种情况,一般都是找出错误,然后修改slave上的数据,然后启动slave,继续应用。
比如上面,要删除的数据在slave上找不到,我们就想知道是删除哪条数据呢?但是show slave status中又没有明确给出错误的语句,因此需要分析binary log来查看是哪条语句。binary log的格式是mixed,初步使用mysqlbinlog查看,发现该条语句是RBR,而不是SBR,因此需要使用--base64-output=decode-rows -v -v选项,如下:
使用binary log:
[root@awstats usr]# /usr/local/mysql5157_2/bin/mysqlbinlog --no-defaults --base64-output=decode-rows -v -v mysql-bin.000034 | grep -A 200 '684728241' > zhh.txt
或者
使用relay log:
[root@mysqldb var]# /usr/local/mysql51572/bin/mysqlbinlog --no-defaults --base64-output=decode-rows -v -v relay-log.000004 | grep -A 200 '684728241' > zhh.txt查看文件,发现以下内容:
#120719 1:01:03 server id 1 end_log_pos 684728241 Delete_rows: table id 16854 flags: STMT_END_F
### DELETE FROM eoc.eoc_course_rank
### WHERE
### @1=2 /* TINYINT meta=0 nullable=0 is_null=0 */
### @2=392 /* SHORTINT meta=0 nullable=0 is_null=0 */
### @3=574 /* INT meta=0 nullable=0 is_null=0 */
### @4='xxx' /* VARSTRING(192) meta=192 nullable=0 is_null=0 */
### @5='yyy' /* VARSTRING(1500) meta=1500 nullable=1 is_null=0 */
### @6='20111202-2df9eef5c0e33cfd643927cb1bb048fa17a40dfa.jpg' /* VARSTRING(600) meta=600 nullable=1 is_null=0 */
### @7=3 /* INT meta=0 nullable=1 is_null=0 */
### @8=256 /* INT meta=0 nullable=1 is_null=0 */
# at 684728241即出错误的语句为:
delete from eoc.eoc_course_rank
where
第一列等于2
第二列等于392
......
根据该表的主键在slave查询,发现where条件中有一个字段值不同,因此在slave上找不到要删除的数据。mysql> use eoc;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> SELECT * FROM eoc_course_rank
-> WHERE course_id=574 \G;
*************************** 1. row ***************************
rank_type: 2
rank_id: 385
course_id: 574
course_name: xxxdetail_info: yyybrief_image: 20111202-2df9eef5c0e33cfd643927cb1bb048fa17a40dfa.jpg
cp_id: 3
grade_id: 256
1 row in set (0.00 sec)ERROR:
No query specifiedmysql> UPDATE eoc_course_rank SET rank_id= 392 WHERE course_id=574;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> commit;
Query OK, 0 rows affected (0.00 sec)mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)mysql> start slave;
Query OK, 0 rows affected (0.00 sec)mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.9.61
Master_User: repl
Master_Port: 3312
Connect_Retry: 60
Master_Log_File: mysql-bin.000034
Read_Master_Log_Pos: 746616004
Relay_Log_File: relay-log.000004
Relay_Log_Pos: 95495411
Relay_Master_Log_File: mysql-bin.000034
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: eoc.%,test.%,mysql.%
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 738390127
Relay_Log_Space: 261893867
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: 4791
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.9.61
Master_User: repl
Master_Port: 3312
Connect_Retry: 60
Master_Log_File: mysql-bin.000034
Read_Master_Log_Pos: 747488636
Relay_Log_File: relay-log.000005
Relay_Log_Pos: 904068
Relay_Master_Log_File: mysql-bin.000034
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: eoc.%,test.%,mysql.%
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 747488636
Relay_Log_Space: 104594214
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:
1 row in set (0.00 sec)上面说了,产生该错误的根本原因是主从数据不一致。为什么主从数据不一致呢?
从报错的时间点分析,发现该错误数据是一个event执行后产生的,查看该event,发现有存在结果集不确定的语句。修改该event的sql,再次执行该event调用的stored procedure,状态仍然为双YES。另外有一点不明白:my.cnf中设置的binary log是mixed格式:在未修改该sql之前,该行数据binary log记录的是RBR格式;修改后记录的是SBR格式。
相关文章推荐
- MySQL主从复制出现Slave_IO_Running,Slave_SQL_Running问题的解决方法
- MySQL的主从复制步骤详解及常见错误解决方法
- mysql 使用GTID主从复制后出现错误代码1785解决方法
- mysql 复制slave服务器数据延迟的原因与解决方法
- 【MySQL】【复制】利用slave_exec_mode处理复制过程中出现的1062与1032错误
- MySQL的主从复制步骤详解及常见错误解决方法
- mysql启动服务报1058错误的解决方法
- mysql中Access denied for user 'root'@'localhost' (using password:YES) 错误的解决方法
- [乐意黎原创]因误删除导致Mysql启动时出现system error 1067 has occurred及Plugin FEDERATED is disabled 错误提示的解决方法
- MySQL启动1053错误解决方法
- mysql同步复制报Slave can not handle replication events with the checksum that master 错误
- MySQL This function has none of DETERMINISTIC, NO SQL...错误1418 的原因分析及解决方法
- linux下mysql提示"mysql deamon failed to start"错误的解决方法
- Windows下MySql错误代码1045的解决方法
- mysql Access denied for user root@localhost错误解决方法
- mysql1045错误解决方法重设管理员密码为空
- MySQL复制出错 Last_SQL_Errno:1146的解决方法
- mysql 发生系统错误1067的解决方法
- MySQL主从复制错误代码:1032 1062 1594解决方案
- MySQL5.6 GTID模式 同步复制跳过报错解决方法