mysql主從復制中出現的error和解救辦法
slave日志中的錯誤代碼1:
[ERROR] Error reading packet from server: Client requested master to start replication from impossible position; the last event was read from 'mysql-bin.000016' at 455562731, the last byte read was read from 'mysql-bin.000016' at 4. ( server_errno=1236)
120725 23:19:17 [ERROR] Slave I/O: Got fatal error 1236 from master when reading data from binary log: 'Client requested master to start replication from impossible position; the last event was read from 'mysql-bin.000016' at 455562', Error_code: 1236
解救辦法: www.2cto.com
先查看主服務器中對應日志文件是否有此行,使用的命令是
mysqlbinlog /YOURPATH/'mysql-bin.000016 >>/test
查找有沒有455562對應的行 或者和這個數字很接近的行 然後使用chang master to 命令跳過這行,命令格式如下
stop slave;
CHANGE MASTER TO MASTER_HOST='192.168.192.45',MASTER_USER='XXXX',MASTER_PASSWORD='XXXX',MASTER_LOG_FILE='mysql-bin.000016',MASTER_LOG_POS=455678;
start slave;
如果你找不到455562或者和這個數字很接近的行,你可以使用如下命令查看'mysql-bin.000016 的行數
ls -la mysql-bin.000016
如果統計的行數遠遠少於455562,你可以跳過這個日志,從下一個日志開始復制,命令如下
stop slave;
CHANGE MASTER TO MASTER_HOST='192.168.192.45',MASTER_USER='backup',MASTER_PASSWORD='weiphone',MASTER_LOG_FILE='mysql-bin.000017',MASTER_LOG_POS=4;
start slave; www.2cto.com
錯誤類型代碼2:
mysql slave Error_code: 1062 1054
如果日志中出現了這樣代碼,可能是錯誤的select,或update操作,master是跳過這些操作,但是被記錄到了二進制日志中,slave會依據二進制中的語句做相同的動作,就會報錯,知道原理了要做的操作就很簡單了
stop slave;
set gloable sql_slave_skip_counter=n; //n為你想跳過錯誤語句的個數
start slave;
如果你不想再遇到這種錯誤,可以寫到slave配置文件中格式如下:
slave_skip_errors = 1062
slave_skip_errors = all //跳過所有類型的錯誤碼
作者 leezqang