在一次不小心电脑突然掉电了,开机开就出来了080922 10:29:01 [Note] Slave SQL thread initialized, starting replication in log mysql-bin.000778 at position 2874108, relay log \' ./relay-bin.003287\' position: 2874245
今天几台MySQL服务器突然停电,重启后复制无法启动,总是报如下错误:
- 08092210:29:01[Note]SlaveSQLthreadinitialized,startingreplicationinlog'mysql-bin.000778'atposition2874108,relaylog'./relay-bin.003287'position:2874245
- 08092210:29:01[Note]SlaveI/Othread:connectedtomaster'replication@192.168.0.10:3306',replicationstartedinlog'mysql-bin.000778'atposition2874108
- 08092210:29:01[ERROR]Errorreadingpacketfromserver:Clientrequestedmastertostartreplicationfromimpossibleposition(server_errno=1236)--phpfensi.com
- 08092210:29:01[ERROR]Gotfatalerror1236:'Clientrequestedmastertostartreplicationfromimpossibleposition'frommasterwhenreadingdatafrombinarylog
为什么会报impossible position呢?打开mysql-bin.000778看看.
- mysqlbinlogmysql-bin.000778>log.sql
- tail-flog.sql
- #at2871574#08092210:20:27serverid2end_log_pos2871601Xid=2516638
- COMMIT/*!*/;
- DELIMITER;
- #Endoflogfile
- ROLLBACK/*addedbymysqlbinlog*/;
- /*!50003SETCOMPLETION_TYPE=@OLD_COMPLETION_TYPE*/
最后一个position是2871574,而从库要从2874108开始,难怪报impossible position,难道是断电时有部分log在缓存中还没来得及写入binglog?无论如何先恢复再说吧.
- stopslave;
- CHANGEMASTERTO
- MASTER_LOG_FILE='mysql-bin.000778',
- MASTER_LOG_POS=2871574;
- startslave;
- showslavestatusG
同步正常,后来查看主库的启动日志中这样一段:
- InnoDB:LastMySQLbinlogfileposition02874108,filename./mysql-bin.000778
- 08092210:22:09InnoDB:Started;logsequencenumber62534366248
- 08092210:22:09[Note]Recoveringafteracrashusingmysql-bin
- 08092210:22:09[Note]Startingcrashrecovery...
- 08092210:22:09[Note]Crashrecoveryfinished.
- 08092210:22:09[Note]/usr/sbin/mysqld:readyforconnections.
这里Last MySQL binlog file position 0 2874108也是错误的,这个信息到底是哪里来的呢?为什么会这样呢?不明白,为了保证以后binglog及时写入,将主库sync_binlog变量设置1.