這篇文章主要介紹了Mysql 5.7從節點配置多線程主從複製的相關資料,文中介紹的非常詳細,對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。
前言
Mysql 採用多執行緒進行複製是從Mysql 5.6 開始支援的內容,但5.6 版本下有缺陷,雖然支援多線程,但是每個資料庫只能一個線程,也就是說如果我們只有一個資料庫,則主從複製時也只有一個線程在工作。相當於還是以前的單線程。 從 Mysql 5.7 開始支援同一資料庫下並行主從複製。不過預設情況下,還是單資料庫單一線程,如果需要使用多線程,需要在從節點進行配置。
Mysql 5.7 對主從複製增加了一個類型,共有兩種類型,如下:
下面的步驟,在從節點上進行設定。
查看目前設定
在開始設定之前,我們先看一下目前設定下的主從複製的行程數。mysql> show processlist; +----+-------------+-----------+------+---------+-------+--------------------------------------------------------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+-------------+-----------+------+---------+-------+--------------------------------------------------------+------------------+ | 1 | system user | | NULL | Connect | 91749 | Waiting for master to send event | NULL | | 2 | system user | | NULL | Connect | 208 | Slave has read all relay log; waiting for more updates | NULL | | 37 | root | localhost | NULL | Query | 0 | starting | show processlist | +----+-------------+-----------+------+---------+-------+--------------------------------------------------------+------------------+ 3 rows in set (0.00 sec)
在下面查看複製類型和平行數量配置
mysql> show variables like 'slave_parallel_type'; +---------------------+----------+ | Variable_name | Value | +---------------------+----------+ | slave_parallel_type | DATABASE | +---------------------+----------+ 1 row in set (0.00 sec)
mysql> show variables like 'slave_parallel_workers'; +------------------------+-------+ | Variable_name | Value | +------------------------+-------+ | slave_parallel_workers | 0 | +------------------------+-------+ 1 row in set (0.01 sec)
配置多執行緒
1、停止從節點複製mysql> stop slave; Query OK, 0 rows affected (0.01 sec)
##
mysql> set global slave_parallel_type='logical_clock'; Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'slave_parallel_type'; +---------------------+---------------+ | Variable_name | Value | +---------------------+---------------+ | slave_parallel_type | LOGICAL_CLOCK | +---------------------+---------------+ 1 row in set (0.01 sec)
mysql> set global slave_parallel_workers=4; Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'slave_parallel_workers'; +------------------------+-------+ | Variable_name | Value | +------------------------+-------+ | slave_parallel_workers | 4 | +------------------------+-------+ 1 row in set (0.00 sec)
mysql> start slave; Query OK, 0 rows affected (0.02 sec)
mysql> show processlist; +----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+ | 37 | root | localhost | NULL | Query | 0 | starting | show processlist | | 38 | system user | | NULL | Connect | 8 | Waiting for master to send event | NULL | | 39 | system user | | NULL | Connect | 7 | Slave has read all relay log; waiting for more updates | NULL | | 40 | system user | | NULL | Connect | 8 | Waiting for an event from Coordinator | NULL | | 41 | system user | | NULL | Connect | 8 | Waiting for an event from Coordinator | NULL | | 42 | system user | | NULL | Connect | 8 | Waiting for an event from Coordinator | NULL | | 43 | system user | | NULL | Connect | 8 | Waiting for an event from Coordinator | NULL | +----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+ 7 rows in set (0.00 sec)
總結#
以上是詳細介紹Mysql5.7從節點配置多執行緒主從複製的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!