mysql> show variables like '%semi%';
+------------------------------------+-------+
| 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_no_slave | ON |
+------------------------------------+-------+
4 rows in set (0.00 sec)
rpl_semi_sync_master_enabled=ON 表示开启半同步复制
rpl_semi_sync_master_timeout=10000 单位为毫秒,即10秒超时,将切换为异步复制
rpl_semi_sync_master_wait_no_slave 表示是否允许master每个事务都要等待slave接收确认。默认为ON,每一个事务都会等待,如果slave crash后,当slave追赶上master的日志时,可以自动的切换为半同步方式。如果为OFF,则slave追赶上后,也不会采用半同步的方式复制了,需要手工配置。
rpl_semi_sync_master_trace_level=32 表示用于开启半同步复制时的调试级别,默认32
补充:
rpl_semi_sync_master_wait_for_slave_count MySQL 5.7.3引入的,该变量设置主库需要等待多少个slave应答,才能返回给客户端,默认为1。
2)状态变量
mysql> show status like '%semi%';
+--------------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------------+--------+
| Rpl_semi_sync_master_clients | 1 |
| Rpl_semi_sync_master_net_avg_wait_time | 21014 |
| Rpl_semi_sync_master_net_wait_time | 126089 |
| Rpl_semi_sync_master_net_waits | 6 |
| Rpl_semi_sync_master_no_times | 1 |
| Rpl_semi_sync_master_no_tx | 1 |
| Rpl_semi_sync_master_status | ON |
| Rpl_semi_sync_master_timefunc_failures | 0 |
| Rpl_semi_sync_master_tx_avg_wait_time | 2186 |
| Rpl_semi_sync_master_tx_wait_time | 4373 |
| Rpl_semi_sync_master_tx_waits | 2 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
| Rpl_semi_sync_master_wait_sessions | 0 |
| Rpl_semi_sync_master_yes_tx | 4 |
+--------------------------------------------+--------+
14 rows in set (0.00 sec)
Rpl_semi_sync_master_status 标记master现在是否是半同步复制状态
Rpl_semi_sync_master_clients 记录支持半同步的slave的个数