在mysql 5.7 中如何开启半同步复制
技术百科
一个新手
发布时间:2017-09-08
浏览: 次 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_Mast
er_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 specified5.查看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
# 写到
相关栏目:
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
AI推广<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
SEO优化<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
技术百科<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
谷歌推广<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
百度推广<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
网络营销<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
案例网站<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
精选文章<?muma echo $count; ?>
】
相关推荐
- C#如何使用Channel C#通道实现异步通信
- c++如何利用doxygen生成开发文档_c++
- 如何在Golang中实现文件下载_Golang文件
- Win11怎么更改电脑名称_Windows 11修
- 如何在Golang中指定模块版本_使用go.mod
- C#怎么创建控制台应用 C# Console Ap
- 如何将文本文件中的竖排字符串转换为横排字符串
- 如何在 Go 中正确测试带 Cookie 的 HT
- PHP怎么接收前端传的时间戳_处理时间戳参数转换技
- php下载安装后swoole扩展怎么安装_异步框架
- Windows服务持续崩溃怎样修复_系统服务保护机
- Win11怎么设置开机自动连接宽带_Windows
- 如何使用Golang实现Web表单数据绑定_自动映
- 如何使用Golang实现负载均衡_分发请求到多个服
- Windows 10怎么隐藏特定更新补丁_Wind
- 如何用正则表达式精确匹配“start”到“end”
- VSC怎样在Linux运行PHP_Ubuntu系统
- 如何使用Golang搭建本地API测试环境_快速验
- c++中的CRTP是什么 c++奇异递归模板模式【
- 如何在 IIS 上为 ASP.NET 6 应用排除
- 如何在 Go 同包不同文件中正确引用结构体
- Python配置文件操作教程_JSONINIYAM
- php怎么捕获异常_trycatch结构处理运行时
- 如何将竖排文本文件转换为横排字符串
- c++23 std::expected怎么用 c+
- 短链接还原php提示内存不足_调整PHP内存限制设
- 如何在Golang中操作嵌套切片指针_Golang
- 如何在Golang中实现并发消息队列消费者_Gol
- php中::能访问全局变量吗_全局作用域与类作用域
- 如何在 Go 中创建包含 map 的 slice(
- Win11怎么设置默认PDF阅读器 Win11修改
- Win11关机快捷键是什么_Win11快速关机方法
- Win11怎么设置鼠标宏_Win11鼠标按键自定义
- mac怎么打开终端_MAC终端Terminal使用
- c++获取当前时间戳_c++ time函数使用详解
- 如何在Golang中实现自定义Benchmark_
- Win11怎么设置任务栏透明_Windows11使
- php和redis连接超时怎么办_phpredis
- Win11搜索不到蓝牙耳机怎么办 Win11蓝牙驱
- c++ atoi和atof函数用法_c++字符数组
- Windows10电脑怎么设置文件权限_Win10
- Python函数缓存机制_lru_cache解析【
- Win10如何卸载预装Edge扩展_Win10卸载
- Windows10电脑怎么设置防火墙出站规则_Wi
- C++如何使用std::transform批量处理
- Win11如何关闭游戏模式 Win11禁用Xbox
- Windows怎样关闭Edge新标签页广告_Win
- PHP主流架构怎么监控运行状态_工具推荐【操作】
- Win11怎么关闭边缘滑动手势_Windows11
- 如何使用Golang实现多重错误处理_Golang

er_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
QQ客服