zoukankan      html  css  js  c++  java
  • MYSQL-使用mysqldump创建数据库快照

    对已经有数据的mysql库创建主从的时候,可以使用mysqldump创建数据库快照

    #--master-data选项会自动加上开启复制需要的"change master to"语句,包含file和position的记录开始位置
    mysql> mysqldump --all-databases --master-data > dbdump.db
    # grep -i "CHANGE MASTER TO"  dbdump2.db  |more
    CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000006', MASTER_LOG_POS=367;
    

    如果没有使用--master-data,需要在执行mysqldump之前执行"flush tables with read lock"命令,获取二进制日志的位置,以及"change master to"等操作,mysqldump执行完毕后还要手动释放锁。

    mysql> flush tables with read lock;
    mysql> show master status;
    +------------------+----------+--------------+------------------+-------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
    +------------------+----------+--------------+------------------+-------------------+
    | mysql-bin.000006 |      367 |              |                  |                   |
    +------------------+----------+--------------+------------------+-------------------+
    1 row in set (0.00 sec)
    
    mysql> 
    
    # mysqldump --all-databases --master-data > dbdump.db
    
    mysql> unlock tables;
    
  • 相关阅读:
    BEC listen and translation exercise 44
    中译英12
    BEC listen and translation exercise 43
    中译英11
    BEC listen and translation exercise 42
    中译英10
    BEC listen and translation exercise 41
    中译英9
    BEC listen and translation exercise 40
    中译英8
  • 原文地址:https://www.cnblogs.com/abclife/p/5085984.html
Copyright © 2011-2022 走看看