这篇文章将为大家详细讲解有关Mysql5.7中怎么实现半同步复制,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

0.系统版本

mysql>selectversion();+------------+|version()|+------------+|5.7.25-log|+------------+1rowinset(0.00sec)

在主上安装和开启

mysql>installpluginrpl_semi_sync_mastersoname'semisync_master.so';QueryOK,0rowsaffected(0.03sec)setglobalrpl_semi_sync_master_enabled=on;

2.在从上安装和开启

mysql>installpluginrpl_semi_sync_slavesoname'semisync_slave.so';QueryOK,0rowsaffected(0.01sec)mysql>setglobalrpl_semi_sync_slave_enabled=on;QueryOK,0rowsaffected(0.00sec)

3.确认是否安装成功

mysql>showvariableslike'%semi%';+-------------------------------------------+------------+|Variable_name|Value|+-------------------------------------------+------------+|rpl_semi_sync_master_enabled|OFF||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|

+-------------------------------------------+------------+6rowsinset(0.00sec)

4.用另一个方法确认是否安装成功

mysql>showplugins;+----------------------------+----------+--------------------+----------------------+---------+|Name|Status|Type|Library|License|+----------------------------+----------+--------------------+----------------------+---------+|binlog|ACTIVE|STORAGEENGINE|NULL|GPL||mysql_native_password|ACTIVE|AUTHENTICATION|NULL|GPL||sha256_password|ACTIVE|AUTHENTICATION|NULL|GPL||CSV|ACTIVE|STORAGEENGINE|NULL|GPL||MEMORY|ACTIVE|STORAGEENGINE|NULL|GPL||InnoDB|ACTIVE|STORAGEENGINE|NULL|GPL||INNODB_TRX|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_LOCKS|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_LOCK_WAITS|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_CMP|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_CMP_RESET|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_CMPMEM|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_CMPMEM_RESET|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_CMP_PER_INDEX|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_CMP_PER_INDEX_RESET|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_BUFFER_PAGE|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_BUFFER_PAGE_LRU|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_BUFFER_POOL_STATS|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_TEMP_TABLE_INFO|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_METRICS|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_FT_DEFAULT_STOPWORD|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_FT_DELETED|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_FT_BEING_DELETED|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_FT_CONFIG|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_FT_INDEX_CACHE|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_FT_INDEX_TABLE|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_SYS_TABLES|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_SYS_TABLESTATS|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_SYS_INDEXES|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_SYS_COLUMNS|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_SYS_FIELDS|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_SYS_FOREIGN|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_SYS_FOREIGN_COLS|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_SYS_TABLESPACES|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_SYS_DATAFILES|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||INNODB_SYS_VIRTUAL|ACTIVE|INFORMATIONSCHEMA|NULL|GPL||MyISAM|ACTIVE|STORAGEENGINE|NULL|GPL||MRG_MYISAM|ACTIVE|STORAGEENGINE|NULL|GPL||PERFORMANCE_SCHEMA|ACTIVE|STORAGEENGINE|NULL|GPL||ARCHIVE|ACTIVE|STORAGEENGINE|NULL|GPL||BLACKHOLE|ACTIVE|STORAGEENGINE|NULL|GPL||FEDERATED|DISABLED|STORAGEENGINE|NULL|GPL||partition|ACTIVE|STORAGEENGINE|NULL|GPL||ngram|ACTIVE|FTPARSER|NULL|GPL||validate_password|ACTIVE|VALIDATEPASSWORD|validate_password.so|GPL||rpl_semi_sync_master|ACTIVE|REPLICATION|semisync_master.so|GPL|+----------------------------+----------+--------------------+----------------------+---------+46rowsinset(0.00sec)


5.参数解释:

rpl_semi_sync_master_enabled##设置为on表示开启了半同步功能rpl_semi_sync_master_timeout##单位是毫秒,表示如果主库等待从库回复消息的时间超过该值,就自动切换为异步复制模式rpl_semi_sync_master_wait_for_slave_count##它控制主库接收多少个从库写事物成功反馈,才返回成功给客户端rpl_semi_sync_master_wait_point##默认值是AFTER_SYNC,含义是主库将每个事物写入binlog,并传递给从库,刷新到中继日志,主库开始等待从库的反馈,接收到从库的回复之后,再提交事物并且返回“commitok”结果给客户端

6.重启从库的io线程让设置生效

stop slave io_thread;

start slave io_thread;

关于Mysql5.7中怎么实现半同步复制就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。