一、 今天手机收到短信报警,提示我mysql复制出错了,急忙登进数据库看,用show slave status查看,发现IO线程是YES,而SQL线程是NO,错误也是某个SQL语句错误,SQL线程是执行中继日志里面的语句,于是我就查看relay-info文件,查看到HOSTNAME-RELAY.000607文件执行到了50911行,于是我就用mysqlbinlog HOSTNAME-RELAY.000607 > 3.sql  查看那一行SQL语句,结果一看,原来是开发的在导表  把master上面的一个数据库导入到一个表中,而slave没有这个数据库 所以导致出错,我就把那个数据库 复制到slave就OK了。

二、错误日志:
090509 10:17:04 [ERROR] Slave SQL: Could not execute Update_rows event on table test.test_product; Corrupted replication event was detected, Error_code: 1610; Corrupted replication event was detected, Error_code: 1610; Corrupted replication event was detected, Error_code: 1610; Table 'test_product' is marked as crashed and should be repaired, Error_code: 1194; handler error HA_ERR_WRONG_IN_RECORD; the event's master log mysql-bin.001202, end_log_pos 22648, Error_code: 1610
090509 10:17:04 [Warning] Slave: Corrupted replication event was detected Error_code: 1610
090509 10:17:04 [Warning] Slave: Corrupted replication event was detected Error_code: 1610
090509 10:17:04 [Warning] Slave: Corrupted replication event was detected Error_code: 1610
090509 10:17:04 [Warning] Slave: Table 'test_product' is marked as crashed and should be repaired Error_code: 1194
090509 10:17:04 [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.001202' position 21794



最近复制出现了这个错误,搞的我头疼了很久。最近网站改版了,所以数据库也做了相应的变动,做了变动之后,我的从服务器复制就出错了,而主服务器运行正常,从服务器错误日志提示表需要修复,于是我就修复,一修复之后就出现主键重复,于是我就找中继日志和二进制日志看相应POS值的语句,发现竟没有记录这个表的INSERT语句,我也很郁闷!~找了很久都没找出来,于是我就手工重新同步数据库(就是用mysqlhotcopy数据库到从服务器上来),再手动change master to重新指定POS值,到了第二天,我去检查,发现还是出现相同的错误,于是我就查看那个主键的值(select opid from uud.order_product order by opid desc limit 1,10;)查看最后十行:
| 45646464554|
| 9120 |
| 9119 |
| 9118 |
| 9117 |
| 9116 |
| 9115 |
| 9114 |
| 9112 |

发现最后一个值很不平常,于是就修复表,修复之后就出现主键重复错误,我就删除重复的键值,再插入值试一试,发现插入值的还是不和逻辑,于是就查看AUTO_INCREMENT(show create table table_name)的这个值到哪来了!不看不知道,发现正是45646464556,不明白这个值为何突然暴跳,我就想是不是我复制数据库文件过来,但是表结构没变,是不是这样导致的错误呢!于是我就手动修复AUTO_INCREMENT这个值。观察了一段时间,发现还是出错,于是到网上问人,经过ivan指点,或许是复制模式的问题,我看了我的默认模式是混合模式,就是binlog=mixed,所以某些SQL语句在二进制日志找不到,是因为SBR模式不记录SQL语句,我把binlog=row也就是改为SBR模式试试,发现AUTO_INCREMENT还是暴跳,并且某些表提示没有默认值,于是我就调成binlog=
AUTO_INCREMENT暴跳呢?这个问题还要待研究

具体mysql复制模式请参见http://xinying.blog.51cto.com/441770/157588