mysql的master和slave同步方案
- 同步原理
- master将改变记录到二进制日志(binary log)中
- slave将master的binary log events拷贝到它的中继日志(relay log)
- slave重做中继日志中的事件,改变自己的数据,相当于执行了master的所有操作

- 同步配置
- master配置
开启binlog vim /etc/my.cnf添加配置
12log_bin = mysql-binserver_id = 1创建复制账号
1GRANTREPLICATION SLAVE,RELOAD,SUPERON*.*TOroot@’slave ip’ IDENTIFIEDBY'password';
- 拷贝数据,如果master有数据而slave没有数据 则需要先把master的数据拷dump到slave中,如果是全新的master和slave(master和slave均没有数据则不需要此步骤)
- slave配置
对master运行
123456SHOW MASTER STATUS;+------------------+-----------+--------------+------------------+-------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |+------------------+-----------+--------------+------------------+-------------------+| mysql-bin.000001 | 686034183 | | | |+------------------+-----------+--------------+------------------+-------------------+- 配置slave
开启binlog vim /etc/my.cnf添加配置
12log_bin = mysql-binserver_id = 1启动slave执行sql
1CHANGE MASTERTOMASTER_HOST='master host', MASTER_USER='root', MASTER_PASSWORD='password',MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=686034183 ;其中的MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=686034183;为上一步在master上执行SHOW MASTER STATUS;的结果
运行
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657SHOW SLAVE STATUS\G;*************************** 1. row ***************************Slave_IO_State: Waitingformastertosend eventMaster_Host: 123.57.207.198Master_User: rootMaster_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000001Read_Master_Log_Pos: 686034183Relay_Log_File: mysqld-relay-bin.000002Relay_Log_Pos: 686034113Relay_Master_Log_File: mysql-bin.000001Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno: 0Last_Error:Skip_Counter: 0Exec_Master_Log_Pos: 686034183Relay_Log_Space: 686034287Until_Condition: NoneUntil_Log_File:Until_Log_Pos: 0Master_SSL_Allowed:NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert:NoLast_IO_Errno: 0Last_IO_Error:Last_SQL_Errno: 0Last_SQL_Error:Replicate_Ignore_Server_Ids:Master_Server_Id: 2Master_UUID: b4afeca0-1c33-11e5-856d-00163e002b08Master_Info_File: /var/lib/mysql/master.infoSQL_Delay: 0SQL_Remaining_Delay:NULLSlave_SQL_Running_State: Slave hasreadallrelay log; waitingforthe slave I/O threadtoupdateitMaster_Retry_Count: 86400Master_Bind:Last_IO_Error_Timestamp:Last_SQL_Error_Timestamp:Master_SSL_Crl:Master_SSL_Crlpath:Retrieved_Gtid_Set:Executed_Gtid_Set:Auto_Position: 01 rowinset(0.00 sec)其中Slave_IO_Running: Yes和Slave_SQL_Running: Yes则为正常,此时开始同步了
- master配置
mysql的master和slave同步方案的更多相关文章
- mysql主从复制 master和slave配置的参数大全
master所有参数1 log-bin=mysql-bin 1.控制master的是否开启binlog记录功能: 2.二进制文件最好放在单独的目录下,这不但方便优化.更方便维护. 3.重新命名二进制日 ...
- RocketMQ多master迁移至多master多slave模式
一.项目背景 由于当前生产环境RocketMQ机器使用年限较长,已经过保,并且其中一台曾经发生过异常宕机事件.并且早期网络规划较乱,生产.开发.测试等网络没有分开,公司决定对当前网络进行规划,区分各个 ...
- 【MySQL】MySQL同步报错-> received end packet from server, apparent master shutdown: Slave I/O thread: Failed reading log event, reconnecting to retry报错解决和分析
[root@db-ft-db-48 ~]# tail -f /mysqlLog/beside_index_err.log 140102 20:42:26 [Note] Slave: received ...
- mysql (master/slave)复制原理及配置
1 复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的数据复制到其它主机(slaves)上,并重 ...
- MySQL伪master+Binlog+同步【转】
MySQL 中drop 等高危误操作后恢复方法 实验目的: 本次实验以恢复drop操作为例,使用不同方法进行误操作的数据恢复. 方法: 利用master同步 :伪master+Binlog+同步(本文 ...
- Mysql在master上查看有哪些slave
mysql> select * from information_schema.processlist as p where p.command = 'Binlog Dump'; 或 mysql ...
- MYSQL 的 MASTER到MASTER的主主循环同步
MYSQL 的 MASTER到MASTER的主主循环同步 刚刚抽空做了一下MYSQL的主主同步.把步骤写下来,至于会出现的什么问题,以后随时更新.这里我同步的数据库是TEST1.环境描述. 主 ...
- mysql5.7主从(Master/Slave)同步配置
环境: mysql版本都是5.7(以前的版本配置可能不一样) 主(Master) windows:192.168.0.68 从(Slave) centos7:192.168.0.4 基本环境配置: 要 ...
- 配置Master与Slave实现主从同步
Mysql版本 通过docker启动的mysql容器 mysql版本 root@1651d1cab219:/# mysql --version mysql Ver 14.14 Distrib 5.6. ...
随机推荐
- Mysql数据库实用语句集
mysql实用语句 (1).从第0行开始取,取3行(一般用于分页)select * from student limit 0,3 (2).查看当前数据库编码 show variables like ' ...
- HDU4910 Problem about GCD
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- Pandas教程目录
Pandas数据结构 Pandas系列 Pandas数据帧(DataFrame) Pandas面板(Panel) Pandas基本功能 Pandas描述性统计 Pandas函数应用 Pandas重建索 ...
- IDEA.环境
1.下载: https://www.jetbrains.com/idea/download/#section=windows 安装的版本是:Ultimate:ideaIU-2017.3.3.exe 2 ...
- git rm -r --cache命令 及 git .gitignore 文件
git 的 .gitignore 文件的作用是在代码提交时自动忽略一个文件.不将其纳入版本控制系统. 比如.一般我们会忽略IDE自动生成的配置文件等. 如果一个你要忽略的文件已经纳入到了git ,也 ...
- Nginx 出现413 Request Entity Too Large得解决方法
Nginx 出现413 Request Entity Too Large得解决方法 默认情况下使用nginx反向代理上传超过2MB的文件,会报错413 Request Entity Too Large ...
- 设计模式--解释器模式C++实现
1定义 给定一门语言,定义他的文法的一种表示,并定义一个解释器,该解释器使用该表示来解释语言中的句子 2类图 角色分析 AbstractExpression抽象解释器,具体的解释任务由各个实现类完成, ...
- bzoj1009: [HNOI2008]GT考试 ac自动机+矩阵快速幂
https://www.lydsy.com/JudgeOnline/problem.php?id=1009 阿申准备报名参加GT考试,准考证号为N位数X1X2....Xn(0<=Xi<=9 ...
- Java中如何获取多维数组的长度
在程序处理中遍历数组是一种很常见的操作,但遍历数组时,我们需要知道数组各维度的长度(一维数组除外,for each 可以遍历),下面举例说明如何求多维数组的长度. 一维 : int [] array ...
- docker nginx 问题
'经常不启动docker会遇到如下问题 启动docker pull * 会报错 1. 安装步骤: 解决办法:命令输入:docker logout 再次执行:docker pull * 2. 执行ru ...