mysql的并行复制的原理以及搭建

摘要:

一、并行复制的背景 首先,为什么会有并行复制这个概念呢?
1. DBA都应该知道,MySQL的复制是基于binlog的。 
2. MySQL复制包括两部分,IO线程 和 SQL线程。 
3. IO线程主要是用于拉取接收Master传递过来的binlog,
并将其写入到relay log
4. SQL线程主要负责解析relay log,并应用到slave中 
5. 不管怎么说,IO和SQL线程都是单线程的,
然后master却是多线程的,所以难免会有延迟,
为了解决这个问题,多线程应运而生了。

实验搭建:

注;此处继续保持之前的实验环境;

主: server4
从: server2

1.编辑配置文件:
vim /etc/my.cnf

slave-parallel-type=LOGICAL_CLOCK  #基于组提交的并行复制方式
slave-parallel-workers=10  #开启多线程复制
master_info_repository=TABLE
relay_log_info_repository=TABLE
relay_log_recovery=ON

 

2.查看是否开启:

1.mysql -p


2.mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
3.
mysql> show tables;
有
slave_master_info  


 


mysql> select * from slave_master_info;
Empty set (0.00 sec)

3.重启msqld:

systemctl restart mysqld

4.
[root@server2 ~]# mysql -p

[root@server2 ~]# mysql -p

5.

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from slave_master_info;



6.

mysql> show tables;

mysql> select * from slave_relay_log_info ;


7.

mysql> show processlist\G;

*************************** 2. row **************
     Id: 2
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 796
  State: Slave has read all relay log; waiting for more updates
   Info: NULL

猜你喜欢

转载自blog.csdn.net/xys2333/article/details/87913541