http://blog.ly5.org/archives/165.html
今天上论坛发现新发表的帖子无法正常显示(论坛数据库采用Mysql主从复制进行读写分离方案),马上想到可能主从复制同步上出现问题,同一时间收 到同事消息说数据库的主复制出现故障重启了,这时找到事故原因主数据库重启了会导致从数据库数据复制同步上延后,过一段时间SSH到从数据库上show slave status\G;查看状态显示
Slave_IO_Running: NO Slave_SQL_Running: Yes ... Last_Errno: 0 Last_Error: ... Seconds_Behind_Master: NULL
从状态信息来看数据同步没有延后也没有报任何的错误,但Slave_IO_Running: NO显示同步IO进程失败。根据以往经验会先重启一下Slave后在show slave status\G;看一下是否会恢复正常,Slave_IO_Running: NO问题还是没有解决于是查看一下Mysql的错误日志发现
090605 9:13:20 [Note] Slave SQL thread initialized, starting replication in log ‘mysql-bin.000102′ at position 1029244974, relay log ‘./xxx-relay-bin.000634′ position: 98 090605 9:13:20 [Note] Slave I/O thread: connected to master ’slave163@192.168.0.131:3306′, replication started in log ‘mysql-bin.000102′ at position 1029244974 090605 9:13:20 [ERROR] Error reading packet from server: Client requested master to start replication from impossible position ( server_errno=1236) 090605 9:13:20 [ERROR] Got fatal error 1236: ‘Client requested master to start replication from impossible position’ from master when reading data from binary log 090605 9:13:20 [Note] Slave I/O thread exiting, read up to log ‘mysql-bin.000102′, position 1029244974 090605 9:13:52 [Note] Error reading relay log event: slave SQL thread was killed
在网上查了很多资料可能因为mysql-bin.000102日志文件中并没有1029244974这个位置,vi打开mysql- bin.000102日志文件搜索1029244974确实没有搜到内容,但为什么主数据库意外的重启会导致Slave上读取位置的错误,记得以前主数据 库也手动重启过Slave上也没有出现过这种问题还请知道的高手帮忙解答一下啊。解决方法是使用CHANGE MASTER TO命令就是让Slave跳过mysql-bin.000102日志文件1029244974这个位置直接到下一个日志文件
SLAVE STOP; CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000103', MASTER_LOG_POS=0; SLAVE START;
但是这样如果mysql-bin.000102日志文件的内容没有同步完会导致主数据库与从数据库的内容不一致,那何不把位置向前移呢
SLAVE STOP; CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000102', MASTER_LOG_POS=1019244974; SLAVE START;
于是试了一把果然Slave_IO_Running: YES同步成功跳过了mysql-bin.000102日志文件1029244974这个位置并继续读取下一个位置,这样从数据库也不会丢失数据和主数据 库保持数据的一致,如果my.cnf中没有加slave-skip-errors参数跳过一些错误的话,同步位置向前移会导致一些数据重新插入到表中报主 键重复错误加上参数就可以成功跳过这些错误了。
相关参数文章:
http://www.cnscn.org/htm_data/288/0904/45920.html
http://hi.baidu.com/leechl/blog/item/b53c6ad48fe64fcc50da4b3e.html
2056

被折叠的 条评论
为什么被折叠?



