默認情況下process如下
mysql> show processlist;
+----+-------------+-----------+--------+---------+-------+--------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+-----------+--------+---------+-------+--------------------------------------------------------+------------------+
| 8 | system user | | NULL | Connect | 70100 | Waiting for master to send event | NULL |//IO線程
| 9 | system user | | NULL | Connect | 57345 | Slave has read all relay log; waiting for more updates | NULL |//中繼線程,單線程
| 10 | root | localhost | master | Query | 0 | starting | show processlist |
+----+-------------+-----------+--------+---------+-------+--------------------------------------------------------+------------------+
3 rows in set (0.00 sec)
開啟并行復制,編輯slave的/etc/my.cnf,新增如下信息
slave-parallel-type=LOGICAL_CLOCK//設置通過組提交,database是幾個數(shù)據(jù)庫就起幾個線程,當只有一個數(shù)據(jù)庫時,一個線程不夠,所以引入組復制,一組一個線程
slave-parallel-workers=16 //并行復制sql線程數(shù)
master_info_repository=TABLE //data/mysql里的master.info和relay-log.info以表的形式存到數(shù)據(jù)庫中
relay_log_info_repository=TABLE
relay_log_recovery=ON//激活中繼日志
重啟mysql后再次進入mysql查看
mysql> show processlist;
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
| 1 | system user | | NULL | Connect | 36 | Waiting for master to send event | NULL |
| 2 | system user | | NULL | Connect | 35 | Slave has read all relay log; waiting for more updates | NULL |
| 3 | system user | | NULL | Connect | 36 | Waiting for an event from Coordinator | NULL |
| 4 | system user | | NULL | Connect | 36 | Waiting for an event from Coordinator | NULL |
| 5 | system user | | NULL | Connect | 36 | Waiting for an event from Coordinator | NULL |
| 6 | system user | | NULL | Connect | 36 | Waiting for an event from Coordinator | NULL |
| 8 | root | localhost | NULL | Query | 0 | starting | show processlist |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
7 rows in set (0.00 sec)
可以看到,多了四條數(shù)據(jù),這四條數(shù)據(jù)代表4個sql線程為協(xié)程線程,等待轉發(fā)