1、首先在master上面安装插件
INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
Query OK, 0 rows affected (0.01 sec)
2、设置master全局变量和超时时间
SET GLOBAL rpl_semi_sync_master_enabled = 1;
Query OK, 0 rows affected (0.00 sec)
查看变量是否开启
show variables like "%semi_sync%";
+-------------------------------------------+------------+
| Variable_name | Value |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 10000 |
| rpl_semi_sync_master_trace_level | 32 |
| rpl_semi_sync_master_wait_for_slave_count | 1 |
| rpl_semi_sync_master_wait_no_slave | ON |
| rpl_semi_sync_master_wait_point | AFTER_SYNC |
+-------------------------------------------+------------+
6 rows in set (0.01 sec)
3、在slave上面安装插件,设置全局变量
INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
Query OK, 0 rows affected (0.00 sec)
SET GLOBAL rpl_semi_sync_slave_enabled = 1;
Query OK, 0 rows affected (0.00 sec)
4、停止slave上面的I/O线程,然后重启I/O线程
STOP SLAVE IO_THREAD;
Query OK, 0 rows affected (0.00 sec)
START SLAVE IO_THREAD;
Query OK, 0 rows affected (0.00 sec)
5、也可以在配置文件里面配置半同步复制(永久开启)
master:
[mysqld]
rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000 # 1 second
slave:
[mysqld]
rpl_semi_sync_slave_enabled=1
6、测试数据一致性
create database test;
Query OK, 1 row affected (1.01 sec)
show databases;
+--------------------+
| Database |
+--------------------+
| test |
use test;
Database changed
show tables;
Empty set (0.00 sec)
create table tt1(id int,name varchar(10));
Query OK, 0 rows affected (0.00 sec)
show tables;
+----------------------+
| Tables_in_zhaojunjie |
+----------------------+
| tt1 |
+----------------------+
1 row in set (0.00 sec)
在slave上面:可以看到数据同步过来了,说明数据一致
show databases;
+--------------------+
| Database |
+--------------------+
| test |
+--------------------+
11 rows in set (0.00 sec)
use test;
Database changed
show tables;
Empty set (0.00 sec)
show tables;
+----------------------+
| Tables_in_zhaojunjie |
+----------------------+
| tt1 |
+----------------------+
1 row in set (0.00 sec)
标签:同步,semi,0.00,sync,复制,master,mysql,sec,rpl
From: https://www.cnblogs.com/qcy-blog/p/18131070