在试Mysql5.6,搭了个主从:
CHANGE MASTER TO MASTER_HOST='1.2.3.4', master_user='slave', master_password='xxxqqq', master_port=5615, MASTER_LOG_FILE='binlog.000001', MASTER_LOG_POS=107;
一切正常。然后在主上建个表,在从上一看没有。再看看状态:
mysql> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Master_Host: 1.2.3.4 Master_User: slave Master_Port: 5615 Connect_Retry: 60 Master_Log_File: binlog.000001 Read_Master_Log_Pos: 107 Relay_Log_File: relaylog.000002 Relay_Log_Pos: 280 Relay_Master_Log_File: binlog.000001 Slave_IO_Running: No Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 107 Relay_Log_Space: 446 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: 1236 Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'log event entry exceeded max_allowed_packet; Increase max_allowed_packet on master; the first event 'binlog.000001' at 107, the last event read from '/mnt/disk1/mysql_5615_binlog/binlog.000001' at 107, the last byte read from '/mnt/disk1/mysql_5615_binlog/binlog.000001' at 126.' Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 3801 Master_UUID: aa8bc3d4-81aa-11e3-9065-001517a25b3a Master_Info_File: /mnt/disk1/mysql_5615/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: 140121 09:10:31 Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 1 row in set (0.00 sec) ERROR: No query specified
确认了我的
max_allowed_packet
是32M,太够了啊。搞了半天无果,后来搜了搜,发现了这个贴子(
http://blog.chinaunix.net/uid-451-id-3087001.html
),说是根本原因是偏移量不对。于是去主上看看:
mysqlbinlog binlog.000001 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #140121 8:45:29 server id 601 end_log_pos 120 CRC32 0xf881fb00 Start: binlog v 4, server v 5.6.15-debug-log created 140121 8:45:29 at startup ROLLBACK/*!*/; BINLOG ' KcPdUg9ZAgAAdAAAAHgAAAAAAAQANS42LjE1LWRlYnVnLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAApw91SEzgNAAgAEgAEBAQEEgAAXAAEGggAAAAICAgCAAAACgoKGRkAAQD7 gfg= '/*!*/; # at 120 #140121 8:45:30 server id 601 end_log_pos 328 CRC32 0x4763204a Query thread_id=2 exec_time=0 error_code=0
于是在从上重新change master to,把偏移量设成120,就一切正常了。
我之前搞Mysql5.5时一直是偏移量107的,到了现在5.6了变成了120,有趣。
另外也是头脑反应慢了些,其实在主上看状态时也应该能反应到的:
mysql> show binary logs; +---------------+-----------+ | Log_name | File_size | +---------------+-----------+ | binlog.000001 | 560 | | binlog.000002 | 372 | | binlog.000003 | 120 | +---------------+-----------+ 3 rows in set (0.03 sec)