mysql replication 延时_MySQL:延迟的主从复制 ( Delayed Replication )
MySQL 5.6 已经支持延迟的流复制, 可设置备节点的延迟时间, 延迟复制是有意义的,例如防止主节点数据误删,查看数据库历史状态等。
重点:延迟复制实在原有的主从复制基础上、所以先要有主从复制的环境,然后配置延迟复制.
一、 语法:CHANGE MASTER TO MASTER_DELAY = 30;---表示延迟30s
备注:设置备节点延迟的时间,单位秒。
二、 配置延迟复制
登录从节点服务器进行设置:root@localhost:mysql>stop slave;
Query OK, 0 rows affected (0.21 sec)
root@localhost:mysql>CHANGE MASTER TO MASTER_DELAY = 30;
Query OK, 0 rows affected (0.17 sec)
root@localhost:mysql>start slave;
Query OK, 0 rows affected (0.27 sec)
三、查看从节点状态root@localhost:mysql>select * from slave_relay_log_info\G
*************************** 1. row ***************************
Number_of_lines: 7
Relay_log_name: ./db2-relay-bin.000007
Relay_log_pos: 281
Master_log_name: bin-log.000041
Master_log_pos: 361
Sql_delay: 30
Number_of_workers: 0
Id: 1
1 row in set (0.00 sec)
root@localhost:mysql>show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.2.37
Master_User: rep1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: bin-log.000040
Read_Master_Log_Pos: 604
Relay_Log_File: db2-relay-bin.000002
Relay_Log_Pos: 281
Relay_Master_Log_File: bin-log.000040
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: 604
Relay_Log_Space: 452
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: 1
Master_UUID: 0c130d47-22bb-11e4-aaaa-000c2986ac80
Master_Info_File: mysql.slave_master_info
SQL_Delay: 30
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
四、主节点创建表测试root@localhost:mysql>create table test_delay(id int4 primary key,
create_time datetime default current_timestamp);
Query OK, 0 rows affected (0.59 sec)
root@localhost:mysql>insert into test_delay (id) values(1);
Query OK, 1 row affected (0.07 sec)
五、备节点查询root@localhost:mysql>select * from test_delay;
Empty set (0.00 sec)
root@localhost:mysql>select * from test_delay;
Empty set (0.00 sec)
这时在备节点上还查不到表。
root@localhost:mysql>show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.2.37
Master_User: rep1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: bin-log.000040
Read_Master_Log_Pos: 1013
Relay_Log_File: db2-relay-bin.000002
Relay_Log_Pos: 281
Relay_Master_Log_File: bin-log.000040
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: 604
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: 15
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: 1
Master_UUID: 0c130d47-22bb-11e4-aaaa-000c2986ac80
Master_Info_File: mysql.slave_master_info
SQL_Delay: 30
SQL_Remaining_Delay: 14
Slave_SQL_Running_State: Waiting until MASTER_DELAY seconds after master executed event
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
root@localhost:mysql>select * from test_delay;
+----+---------------------+
| id | create_time |
+----+---------------------+
| 1 | 2014-12-12 14:38:47 |
+----+---------------------+
1 row in set (0.00 sec)
六、备注: 发现备节点在 30 秒后才能查到新建的表,这里有三个字段显示延迟的信息:
SQL_Delay: 显示已设置的主备延迟的时间,单位秒;
SQL_Remaining_Delay: 显示剩余的主备延迟时间,单位秒;
Slave_SQL_Running_State: 表示 SQL thread 状态;
mysql replication 延时_MySQL:延迟的主从复制 ( Delayed Replication )相关推荐
- mysql使用主从复制迁移,[MySQL进阶之路][No.0003] 主从复制(Replication)在运维中的运用...
前序 在之前的两章里,主要介绍的主从复制(Replication)的基本使用方法和show slave status一些基本参数,这一章我们讲一下主从复制在生产环境中的一些在运维中的常见用途.下面将要 ...
- mysql部署策略_MySQL延迟问题和数据刷盘策略流程分析
一.MySQL复制流程 官方文档流程如下: MySQL延迟问题和数据刷盘策略 1.绝对的延时,相对的同步 2.纯写操作,线上标准配置下,从库压力大于主库,最起码从库有relaylog的写入. 二.My ...
- mysql数据库主文件_mysql数据库的主从复制和主主复制
Mysql主从架构技术说明 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机(Master)的数据复制到其 ...
- mysql做心跳_MySQL运维-主从复制心跳
1 心跳参数简介 设置复制心跳的周期,取值范围为0 到 4294967秒.精确度可以达到毫秒,最小的非0值是0.001秒.心跳信息由master在主机binlog日志文件在设定的间隔时间内没有收到新的 ...
- Java mysql同步复制_MySQL数据的主从复制、半同步复制和主主复制详解
一.MySQL复制概述 ⑴.mysql数据的复制的基本介绍 目前MySQL数据库已经占去数据库市场上很大的份额,其一是由于MySQL数据的开源性和高性能,当然还有重要的一条就是免费~不过不知道还能免费 ...
- mysql delayed_Mysql:Delayed Replication:延迟复制
语法很简单,意义却很重大! 16.3.10 Delayed Replication MySQL 5.7 supports delayed replication such that a slave s ...
- mysql 5.5 主从同步问题_MySQL 5.5 主从复制异步、半同步以及注意事项详解
大纲 一.前言 二.Mysql 基础知识 三.Mysql 复制(Replication) 四.Mysql 复制(Replication)类型 五.Mysql 主从复制基本步骤 六.Mysql 主从复制 ...
- mysql主从应用_MySQL主从复制应用、主从复制原理
mysql主从复制安装配置 1.基础设置准备 #操作系统: centos6.5 #mysql版本: 5.7 #两台虚拟机: node1:192.168.85.111(主) node2:192.168. ...
- mysql主从 毫秒_MySQL主从数据库同步延迟问题解决(转)
最近在做MySQL主从数据库同步测试,发现了一些问题,其中主从同步延迟问题是其中之一,下面内容是从网上找到的一些讲解,记录下来以便自己学习: MySQL的主从同步是一个很成熟的架构,优点为:①在从服务 ...
最新文章
- GPT-3距离下一代AI生态平台还有多远?
- GSMA:中国有望成为全球领先的5G市场之一
- python爬取地图上的经纬度_Python调用百度地图API爬取经纬度
- 机器学习中的不平衡分类方法(part5)--决策树与随机森林
- 【Transformer】TransMix: Attend to Mix for Vision Transformers
- 详细解释signal和sigaction以及SIG_BLOCK
- [html] input如何在各个浏览器下保持UI统一?
- 腾讯或联姻优酷,微信嫁女模式引发互联网通婚潮流
- 阿里女员工遭遇「杀猪盘」背后的思考
- 计算机三级之嵌入式系统学习笔记5
- memset 和 memcpy 和 memcmp (strncmp遇到\0会中断)
- MySQL下载安装、配置与使用(win7x64)
- An internal error occurred during: Launching web on MyEclipse Tomcat
- jQuery.ajax 调用 服务(.aspx,.asmx)
- AIM Tech Round 5 (rated, Div. 1 + Div. 2)
- 【图像边缘检测】基于matlab最小二乘法椭圆边缘检测【含Matlab源码146期】
- 计算机财务管理模型的建立步骤,计算机财务管理系统的建立.ppt
- 艺体计算机教师考核细则,音体美教师考核办法
- 【ElectronJs】基于Electron Forge打包的一些问题汇总
- C#:using和new关键字
热门文章
- 上传图片到服务器不能马上响应,用post方式上传图片到服务器
- RHEL4As RAC手记
- Linux时间子系统之(五):POSIX Clock
- Beta Daily Scrum 第五天
- 前端学习之touch.js与swiper学习
- bzoj2150,poj1422,poj1548
- ROS Nodelet使用
- oracle 11g nlslang,常用数学符号的 LaTeX 表示方法
- php sqlite存入文件夹,PHP_小文件php+SQLite存储方案,我们草根站长购买的虚拟主机 - phpStudy...
- Ubuntu系统(四)-修改主机名和配置DNS上网