開啟多執行緒複製,預設關鍵的引數有兩個:
mysql> show variables like 'slave_parallel_%';
+------------------------+---------------+
| Variable_name | Value |
+------------------------+---------------+
| slave_parallel_type | database |
| slave_parallel_workers | 0 |
+------------------------+---------------+
2 rows in set (0.00 sec)
slave-parallel-type 預設值為database
slave-parallel-workers 預設值為0
線上開啟:
mysql> stop slave sql_thread;
Query OK, 0 rows affected (0.07 sec)
mysql> set global slave_parallel_type='LOGICAL_CLOCK';
Query OK, 0 rows affected (0.00 sec)
mysql> set global slave_parallel_workers=4;
Query OK, 0 rows affected (0.00 sec)
mysql> start slave sql_thread;
Query OK, 0 rows affected (0.06 sec)
優化選項:
啟用table模式是因為如果在多執行緒模式下,會頻繁更新master.info檔案,消耗代價過高,並且此值也不是非常準確
master_info_repository=table 對應的表為mysql.slave_master_info
relay_log_recovery=on
relay_log_info_repository=table 對應的表為mysql.slave_relay_log_info
說了這麼多,要開啟enhanced multi-threaded slave其實很簡單,只需根據如下設定:
# slave slave-parallel-type=LOGICAL_CLOCK slave-parallel-workers=16 master_info_repository=TABLE relay_log_info_repository=TABLE relay_log_recovery=ON