| Slave 版本 | 相容 Master 版本 | 備註 |
|---|---|---|
| 3.23.x | 3.23.x | 不可連 4.x Master |
| 4.0.0 | 4.0.0 | 僅限同版本 |
| 4.0.1+ | 3.23.x / 4.x | Master 版本 ≥ Slave 版本 |
| 5.0+ | 5.0+ / 5.1+ / 5.5+ | 建議同主版本,跨大版本需測試 |
黃金法則:同主版本、同次版本、盡量用最新穩定版。
server-id(Master 1、Slave 2、級聯遞增)。GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'slave_host' IDENTIFIED BY 'pass';mysqldump --master-data=2 --single-transaction 導出含 Binlog 座標的備份 → Slave 匯入。server-id=1; log-bin=mysql-bin;重啟;RESET MASTER 清理舊 Binlog。server-id=2; master-host=...; master-user=...; master-password=...; master-connect-retry=30; master-retry-count=100000;重啟。SHOW SLAVE STATUS\G 確認雙線程 Running、延遲 0。STOP/START SLAVE [IO_THREAD|SQL_THREAD]:分線程暫停/恢復(備份時暫停 SQL Thread 獲取一致性快照)。SHOW SLAVE STATUS:監控 Seconds_Behind_Master、Last_Error。PURGE MASTER LOGS TO 'binlog.000123':清理所有 Slave 已處理的 Binlog。CHANGE MASTER TO ...:動態調整同步座標、Master 地址、壓縮協定等。Master binlog-ignore-db=mysql 排除系統庫;Slave replicate-do-db=business_db 僅同步業務庫。