1. 同步原理
    1. master将改变记录到二进制日志(binary log)中
    2. slave将master的binary log events拷贝到它的中继日志(relay log)
    3. slave重做中继日志中的事件,改变自己的数据,相当于执行了master的所有操作
    4. 同步配置
      • master配置

        • 开启binlog vim /etc/my.cnf添加配置

          1
          2
          log_bin   = mysql-bin
          server_id = 1
        • 创建复制账号

          1
          GRANTREPLICATION SLAVE,RELOAD,SUPER ON*.*  TOroot@’slave ip’  IDENTIFIED BY'password';
      • 拷贝数据,如果master有数据而slave没有数据 则需要先把master的数据拷dump到slave中,如果是全新的master和slave(master和slave均没有数据则不需要此步骤)
      • slave配置
        • 对master运行

          1
          2
          3
          4
          5
          6
          SHOW MASTER STATUS;
          +------------------+-----------+--------------+------------------+-------------------+
          | File             | Position  | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
          +------------------+-----------+--------------+------------------+-------------------+
          | mysql-bin.000001 | 686034183 |              |                  |                   |
          +------------------+-----------+--------------+------------------+-------------------+
        • 配置slave
          • 开启binlog vim /etc/my.cnf添加配置

            1
            2
            log_bin   = mysql-bin
            server_id = 1
          • 启动slave执行sql

            1
            CHANGE MASTER TOMASTER_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;的结果

          • 运行

            1
            2
            3
            4
            5
            6
            7
            8
            9
            10
            11
            12
            13
            14
            15
            16
            17
            18
            19
            20
            21
            22
            23
            24
            25
            26
            27
            28
            29
            30
            31
            32
            33
            34
            35
            36
            37
            38
            39
            40
            41
            42
            43
            44
            45
            46
            47
            48
            49
            50
            51
            52
            53
            54
            55
            56
            57
            SHOW SLAVE STATUS\G;
            *************************** 1. row ***************************
                           Slave_IO_State: Waiting formaster tosend event
                              Master_Host: 123.57.207.198
                              Master_User: root
                              Master_Port: 3306
                            Connect_Retry: 60
                          Master_Log_File: mysql-bin.000001
                      Read_Master_Log_Pos: 686034183
                           Relay_Log_File: mysqld-relay-bin.000002
                            Relay_Log_Pos: 686034113
                    Relay_Master_Log_File: mysql-bin.000001
                         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: 686034183
                          Relay_Log_Space: 686034287
                          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: 2
                              Master_UUID: b4afeca0-1c33-11e5-856d-00163e002b08
                         Master_Info_File: /var/lib/mysql/master.info
                                SQL_Delay: 0
                      SQL_Remaining_Delay: NULL
                  Slave_SQL_Running_State: Slave has readallrelay log; waiting forthe slave I/O thread toupdateit
                       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 inset(0.00 sec)

            其中Slave_IO_Running: Yes和Slave_SQL_Running: Yes则为正常,此时开始同步了

mysql的master和slave同步方案的更多相关文章

  1. mysql主从复制 master和slave配置的参数大全

    master所有参数1 log-bin=mysql-bin 1.控制master的是否开启binlog记录功能: 2.二进制文件最好放在单独的目录下,这不但方便优化.更方便维护. 3.重新命名二进制日 ...

  2. RocketMQ多master迁移至多master多slave模式

    一.项目背景 由于当前生产环境RocketMQ机器使用年限较长,已经过保,并且其中一台曾经发生过异常宕机事件.并且早期网络规划较乱,生产.开发.测试等网络没有分开,公司决定对当前网络进行规划,区分各个 ...

  3. 【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 ...

  4. mysql (master/slave)复制原理及配置

    1 复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的数据复制到其它主机(slaves)上,并重 ...

  5. MySQL伪master+Binlog+同步【转】

    MySQL 中drop 等高危误操作后恢复方法 实验目的: 本次实验以恢复drop操作为例,使用不同方法进行误操作的数据恢复. 方法: 利用master同步 :伪master+Binlog+同步(本文 ...

  6. Mysql在master上查看有哪些slave

    mysql> select * from information_schema.processlist as p where p.command = 'Binlog Dump'; 或 mysql ...

  7. MYSQL 的 MASTER到MASTER的主主循环同步

    MYSQL 的 MASTER到MASTER的主主循环同步   刚刚抽空做了一下MYSQL的主主同步.把步骤写下来,至于会出现的什么问题,以后随时更新.这里我同步的数据库是TEST1.环境描述.   主 ...

  8. mysql5.7主从(Master/Slave)同步配置

    环境: mysql版本都是5.7(以前的版本配置可能不一样) 主(Master) windows:192.168.0.68 从(Slave) centos7:192.168.0.4 基本环境配置: 要 ...

  9. 配置Master与Slave实现主从同步

    Mysql版本 通过docker启动的mysql容器 mysql版本 root@1651d1cab219:/# mysql --version mysql Ver 14.14 Distrib 5.6. ...

随机推荐

  1. Windows下安装mayavi2

    由于要使用mayavi2画三维图,但是没有找到二进制包,所以只能安装pythonxy或者canopy之类的版本,后来在http://www.lfd.uci.edu/~gohlke/pythonlibs ...

  2. MATLAB 图形图像处理

    theme: MATLAB author: pprp date: 2018/2/2 --- MATLAB 图形图像处理 二维绘图命令 plot 线性空间 plot(t,[x1,x2,x3]) : 在同 ...

  3. Rank - 第二类斯特灵数

    2017-08-10 20:32:37 writer:pprp 题意如下: Recently in Teddy's hometown there is a competition named &quo ...

  4. Python学习札记(十二) Function3 函数参数一

    参考:函数参数 Note 1.Python的函数定义非常简单,但灵活度却非常大.除了正常定义的必选参数外,还可以使用默认参数.可变参数和关键字参数,使得函数定义出来的接口,不但能处理复杂的参数,还可以 ...

  5. Generator 函数的异步应用

    异步编程对 JavaScript 语言太重要.Javascript 语言的执行环境是“单线程”的,如果没有异步编程,根本没法用,非卡死不可.本章主要介绍 Generator 函数如何完成异步操作. 传 ...

  6. python调用虹软2.0第二版

    第一版踩了无数的坑,终于第二版把坑全添了,这次更新可以正常获取人脸数,角度,代码可读性更高,继续更新中 第三版已发出 https://www.cnblogs.com/wxt51/p/10125460. ...

  7. MVVM中轻松实现Command绑定任意事件的Command

    下面是“银光中国”(不错的WPF或SL网站)WPF学习教程中的一个连接, http://www.silverlightchina.net/html/study/WPF/2011/0715/9034.h ...

  8. linux下查看进程路径

    在linux下查看进程大家都会想到用 ps -ef|grep XXX可是看到的不是全路径,怎么看全路径呢?每个进程启动之后在 /proc下面有一个于pid对应的路径例如:ps -ef|grep pyt ...

  9. 学习 nginx (持续更新)

    什么是代理与反向代理,有什么应用场景? 平常经常听别人说代理与反向代理,那么这二者到底有什么区别呢? 代理 场景:我需要访问一个服务器C,但是由于某些原因我无法访问到它,(典型的就是你FQ,然后fai ...

  10. jmeter-00 JMeter 运行过程

    一.GUI mode 图形化界面运行 to run JMeter, run the jmeter.bat (for Windows) or jmeter (for Unix) file. These ...