Mysql-Replication
MySQL 複製恢復
主伺服器崩潰後,我無法同步從伺服器。您能否告知是否可以恢復(沒有數據/事務失去)或者我是否必須創建一個新的從伺服器?
請注意,在此錯誤之後我彎下腰:
mysql> SHOW SLAVE STATUS \G *************************** 1. row *************************** Slave_IO_State: Master_Host: 192.168.1.1 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000010 Read_Master_Log_Pos: 940132528 Relay_Log_File: cb1s-relay-bin.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: mysql-bin.000010 Slave_IO_Running: No Slave_SQL_Running: No 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: 940132528 Relay_Log_Space: 107 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: 'Client requested master to start replication from impossible position; the first event 'mysql-bin.000010' at 940132528, the last event read from './mysql-bin.000010' at 4, the last byte read from './mysql-bin.000010' at 4.' Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 1 row in set (0.00 sec)
日誌:
120711 13:04:24 [Note] Slave I/O thread: connected to master 'user@192.168.1.1:3306',replication started in log 'mysql-bin.000010' at position 940132528 120711 13:04:24 [ERROR] Error reading packet from server: Client requested master to start replication from impossible position; the first event 'mysql-bin.000010' at 940132528, the last event read from './mysql-bin.000010' at 4, the last byte read from './mysql-bin.000010' at 4. ( server_errno=1236) 120711 13:04:24 [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 first event 'mysql-bin.000010' at 940132528, the last event read from './mysql-bin.000010' at 4, the last byte read from './mysql-bin.000010' at 4.', Error_code: 1236 120711 13:04:24 [Note] Slave I/O thread exiting, read up to log 'mysql-bin.000010', position 940132528 120711 13:04:24 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000010' at position 940132528, relay log './cb1s-relay-bin.000026' position: 940132674 120711 13:05:08 [Note] Error reading relay log event: slave SQL thread was killed 120711 13:06:20 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000010' at position 940132528, relay log './cb1s-relay-bin.000027' position: 4
您不必創建新的從站。您只需要重放主伺服器的數據並重新設置從伺服器(
CHANGE MASTER TO ...
)上的複制座標,如MySQL 文件中所述。通過在 mysqldump 呼叫中指定–master-data=2選項,您可以在不停止數據庫的情況下從主伺服器上獲取數據- 這會將轉儲的複制座標寫入
mysqldump
輸出。請注意,執行 mysqldump仍然可能意味著數據庫支持的應用程序的停機時間,因為在轉儲期間所有表都將被讀鎖定。
另一種選擇是按照David Schwartz 在對您的問題的評論中建議的那樣重置複製座標,並使用Percona 工具包中的 pt-table-sync 將所有表的數據重播到從屬設備以確保完整性。