› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
ansheng
V2EX  ›  MySQL

我所理解的 MySQL 主从复制有错误吗?

  •  
  •   ansheng ·
    anshengme · Oct 20, 2016 · 3057 views
    This topic created in 3628 days ago, the information mentioned may be changed or developed.

    master-slave-replication

    再解释 MySQL 主从复制之前我们需要先启动 Master 数据库然后再启动 Salve 数据库,然后在 Salve 数据库中执行 start slave;,执行完成之后,流程就如下了:

    1. Salve 的 IO 线程会读取 mastr.info 文件中配置好的主库信息,比如说存放的有: Master 数据库的用户名、密码、端口、还有 Master 的 binlog 索引位置;
    2. 拿到信息之后就带着信息去链接 Master 的主库 IO 线程
    3. 当主库的 IO 线程先检查 SLave 传过来的配置信息是否正确,如果正确,就拿着 Slave 传过来的 binlog 索引位置和 Master 库的 binlog 文件中最后一个索引位置进行对比,如果一致就陷入等待状态,等待 Master 的 binlog 索引位置更新;
    4. 如果不一致就把 Slave 传过来的 binlog 索引位置往后的所有 SQL 语句包括最后一条 SQL 语句的索引位置发送个给 Slave 的 IO 线程;
    5. Slave 的 IO 线程拿到信息之后,先把 Master 传过来的 binlog 索引在 Slave 的 master.info 文件中进行更新;
    6. 然后再把 Master 传过来的 SQL 语句写入到 relay 文件中,然后继续循环执行第二个步骤;
    7. Slave 的 SQL 线程会一直持续的观察 relay 日志文件中是否有改动,如果没有就继续监听;
    8. 如果发现 relay 中有变动,那么就获取变动的内容转换为 SQL 语句,并且把 SQL 语句在 Salve 的数据库中进行执行

    阅读原文

    7 replies  •  2016-11-14 18:03:14 +08:00
    julyclyde
        1
    julyclyde  
       Oct 20, 2016
    先把 slave 拼写正确再理解
    julyclyde
        2
    julyclyde  
       Oct 20, 2016
    麻烦你把 master.info 也写对
    ansheng
        3
    ansheng  
    OP
       Oct 20, 2016
    @julyclyde = =.不是 slave 那是撒,
    julyclyde
        4
    julyclyde  
       Oct 20, 2016
    @ansheng 是 slave ;但你写的不是 slave
    ansheng
        5
    ansheng  
    OP
       Oct 20, 2016
    @julyclyde 我写的是啊
    julyclyde
        6
    julyclyde  
       Oct 21, 2016
    @ansheng 我觉得你真不是学工科的那块料了,你缺乏最基本的认真
    mlixuequan
        7
    mlixuequan  
       Nov 14, 2016
    分析的不错,学习了.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1387 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 16:46 · PVG 00:46 · LAX 09:46 · JFK 12:46
    ♥ Do have faith in what you're doing.