mysql 5.7 同步复制_在mysql 5.7 中如何开启半同步复制
1.安装相关的插件show plugins; 查看模块
help --uninstall; 查看卸载模块master:
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so'; --安装 semisync_master.so插件
Query OK, 0 rows affected (0.03 sec)
slave:
root@localhost [zw3306]>install plugin rpl_semi_sync_slave soname 'semisync_slave.so'; --安装 semisync_slave.so插件
Query OK, 0 rows affected (0.00 sec)
root@localhost [zw3306]>install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.00 sec)
2.修改的参数:set global rpl_semi_sync_master_enabled=1;
set global rpl_semi_sync_master_timeout=1000;
set global rpl_semi_sync_slave_enabled=1;
也可以直接写到配置文件 [mysqld]master:
[mysqld]
rpl_semi_sync_master_enabled = 1
rpl_semi_sync_master_timeout = 1000 # 1 second
slave:
[mysqld]
rpl_semi_sync_slave_enabled = 1
修改了参数需要重启:
查看修改的参数master:
mysql> show global variables like '%rpl_semi%';+-------------------------------------------+------------+
| Variable_name | Value |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 1000 |
| 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.00 sec)
slave:
root@localhost [(none)]>show global variables like '%rpl_semi%';+-------------------------------------------+------------+
| Variable_name | Value |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 1000 |
| 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 |
| rpl_semi_sync_slave_enabled | ON |
| rpl_semi_sync_slave_trace_level | 32 |
+-------------------------------------------+------------+
8 rows in set (0.00 sec)
如果:如果原来是已经建好的复制结构很简单:stop slave io_thread;
start slave io_thread;
3.做同步change master to master_host='192.168.26.233', master_port=3306, master_user='repl',master_password='repl', master_auto_position=1;
root@localhost [(none)]>start slave;
Query OK, 0 rows affected (0.01 sec)
root@localhost [(none)]>show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.26.233
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 194
Relay_Log_File: relay-bin.000004
Relay_Log_Pos: 407
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 194
Relay_Log_Space: 861
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 3306100
Master_UUID: 7e354a2c-6f5f-11e6-997d-005056a36f08
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 7e354a2c-6f5f-11e6-997d-005056a36f08:1-9
Executed_Gtid_Set: 7e354a2c-6f5f-11e6-997d-005056a36f08:1-9,
ba0d5587-74d6-11e6-ab5c-005056a3f46e:1-2
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified
5.查看slave是否有数据root@localhost [zw3306]>show tables;
+------------------+
| Tables_in_zw3306 |
+------------------+
| t1 |
+------------------+
1 row in set (0.00 sec)
root@localhost [zw3306]>select * from t1;+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
+------+
4 rows in set (0.00 sec)
6. 怎么确认是同步还是半同步?show global variables like '%semi%';
show global status like '%semi%';master:
root@localhost [zw3306]>show global status like '%semi%';+--------------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients | 1 | 有多少个Semi-sync的备库
| Rpl_semi_sync_master_net_avg_wait_time | 0 | 事务提交后,等待备库响应的平均时间
| Rpl_semi_sync_master_net_wait_time | 0 | 等待网络响应的总次数
| Rpl_semi_sync_master_net_waits | 7 | 总的网络等待时间
| Rpl_semi_sync_master_no_times | 0 | 一共有几次从Semi-sync跌回普通状态
| Rpl_semi_sync_master_no_tx | 0 | 库未及时响应的事务数,如果这个值很大就有问题
| Rpl_semi_sync_master_status | ON | 主库上Semi-sync是否正常开启
| Rpl_semi_sync_master_timefunc_failures | 0 | 时间函数未正常工作的次数
| Rpl_semi_sync_master_tx_avg_wait_time | 410 | 开启Semi-sync,事务返回需要等待的平均时间
| Rpl_semi_sync_master_tx_wait_time | 2876 | 事务等待备库响应的总时间
| Rpl_semi_sync_master_tx_waits | 7 | 事务等待备库响应的总次数
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 | 改变当前等待最小二进制日志的次数
| Rpl_semi_sync_master_wait_sessions | 0 | 当前有几个线程在等备库响应
| Rpl_semi_sync_master_yes_tx | 7 | Semi-sync模式下,成功的事务数
+--------------------------------------------+-------+
15 rows in set (0.00 sec)
root@localhost [zw3306]>show global variables like '%semi%';+-------------------------------------------+------------+
| Variable_name | Value |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 1000 |
| 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 |
| rpl_semi_sync_slave_enabled | ON |
| rpl_semi_sync_slave_trace_level | 32 |
+-------------------------------------------+------------+
8 rows in set (0.00 sec)
Rpl_semi_sync_master_no_tx如果这个值很大就有问题
也有其他的原因;mysql> show global status like '%semi%';+--------------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients | 1 |
| Rpl_semi_sync_master_net_avg_wait_time | 0 |
| Rpl_semi_sync_master_net_wait_time | 0 |
| Rpl_semi_sync_master_net_waits | 17 |
| Rpl_semi_sync_master_no_times | 1 |
| Rpl_semi_sync_master_no_tx | 10 | 不是用半同步复制的
| Rpl_semi_sync_master_status | OFF |
| Rpl_semi_sync_master_timefunc_failures | 0 |
| Rpl_semi_sync_master_tx_avg_wait_time | 410 |
| Rpl_semi_sync_master_tx_wait_time | 2876 |
| Rpl_semi_sync_master_tx_waits | 7 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
| Rpl_semi_sync_master_wait_sessions | 0 |
| Rpl_semi_sync_master_yes_tx | 7 |
+--------------------------------------------+-------+
14 rows in set (0.01 sec)
操作10个事物,可以发现都是 Rpl_semi_sync_master_no_tx
master接收到N个slave的应答后,才commit事物,等待1s用户可以设置应道slave的数量。
rpl_semi_sync_master_wait_for_slave_count=1 默认是1
set global rpl_semi_sync_master_wait_for_slave_count=2;
意思是多少个半同步的slave;
mysql 5.7 同步复制_在mysql 5.7 中如何开启半同步复制相关推荐
- mysql 基于gtid复制_深入MySQL复制(二):基于GTID复制
相比传统的MySQL复制,gtid复制无论是配置还是维护都要轻松的多.本文对gtid复制稍作介绍. 1.gtid基本概念 传统的基于binlog position复制的方式有个严重的缺点:如果slav ...
- mysql 远程复制_关于mysql的复制
概述 复制允许将来自一个MySQL数据库服务器(主服务器)的数据复制到一个或多个MySQL数据库服务器(从服务器). 默认情况下,复制是异步的 从站不需要永久连接以接收来自主站的更新. 根据配置,您可 ...
- mysql 复制技术有什么用_简述MySQL复制的优点
MySQL复制是指从一个mysql服务器(MASTER)将数据通过日志的方式经过网络传送到另一台或多台mysql服务器(SLAVE),然后在slave上重放(replay或redo)传送过来的日志,以 ...
- mysql数据没有同步更新_解决MySQL的主从数据库没有同步的两种方法
问题 今天发现Mysql的主从数据库没有同步 先上Master库: mysql>show processlist; 查看下进程是否Sleep太多.发现很正常. show master statu ...
- mysql 多线程并行复制_【MySQL】开启并行复制
[MySQL]开启并行复制 一.介绍 在官方的 5.6 版本之前,MySQL 只支持单线程复制,由此在主库并发高.TPS 高时就会出现严重的主备延迟问题. 如果备库执行日志的速度持续低于主库生成日志的 ...
- mysql同步数据_实现MySQL数据库数据的同步方法介绍
做开发的时候要做MySQL的数据库同步,两台安装一样的系统,都是FreeBSD5.4,安装了Apache 2.0.55和PHP 4.4.0,MySQL的版本是4.1.15,都是目前最新的版本. 1.安 ...
- mysql innodb 设置详解_【mysql】mysql innodb 配置详解
MySQLinnodb 配置详解 innodb_buffer_pool_size:这是InnoDB最重要的设置,对InnoDB性能有决定性的影响.默认的设置只有8M,所以默认的数据库设置下面InnoD ...
- mysql主从切换gtid不一致_解决mysql使用GTID主从复制错误问题
解决mysql使用GTID主从复制错误问题 做MySQL主从的话肯定会遇到很多同步上的问题, 大多数都是由于机器宕机,重启,或者是主键冲突等引起的从服务器停止工作, 这里专门收集类似问题并提供整理解决 ...
- keepalived mysql双主架构图_基于MySQL双主的高可用解决方案理论及实践
MySQL在互联网应用中已经遍地开花,但是在银行系统中,还在生根发芽的阶段.本文记录的是根据某生产系统实际需求,对数据库高可用方案从需求.各高可用技术特点对比.实施.测试等过程进行整理,完善Mysql ...
最新文章
- iOS之深入解析WKWebView加载的生命周期与代理方法
- 2017年第八届蓝桥杯 - 省赛 - C/C++大学A组 - B. 跳蚱蜢
- 【STM32】FreeRTOS资源(持续更新)
- ios numlock_从“提示”框:默认情况下启用NumLock,无广告的iOS应用和立体声供电的派对灯...
- 今天的你,又被带节奏了吗?
- vue.js+webpack 为 img src 赋值的路径问题解决方法
- CodeForces 521D nice贪心
- 干货 | 平面设计、UI 设计和视觉设计的区别
- SketchUp + Ruby 二次开发初识
- 微信小程序登录-开发文档
- Android 音频系统
- 夏雨老师告诉您学习平面设计到底好不好呢?
- MySQL超市会员管理系统_PHP+MYSQL药店会员管理系统的设计与实现
- 小卡的土豆园开园了~
- 盘古开源丨数据大爆炸时代,云存储成为企业存储必然发展方向
- 运放稳定性连载12:RO何时转变为ZO?(1)
- 孙昌勋:打入奢侈品牌,MStar高端路线胜MTK一筹
- 开学splay(这个模版要背的滚瓜烂熟)
- 加利福尼亚大学计算机排名,加利福尼亚大学洛杉矶分校计算机科学专业排名第13(2020年USNEWS美国排名)...
- java 判断是否包含中文_Java中判断字符串中是否包含中文汉字
热门文章
- 如何让地面不起灰_水泥地面防起灰有什么办法? 水泥地面为什么会起灰?
- 实践数据湖iceberg 第三十七课 kakfa写入iceberg的 icberg表的 enfource ,not enfource测试
- 使用Tesseract和Python进行OCR和语言翻译
- LoRa扩频技术RF芯片SX1276
- Unity-Android常见的那些骚操作
- React Conf 2018大会发布React Hooks和React 16.7 Alpha
- JESD204接口调试总结——Xilinx JESD204C IP工程应用
- VUE---学习进阶08
- 浅谈两军问题拜占庭将军问题
- 第二课第二周第1-5节-基于树的模型用于医学预后