• 【MySQL】mysqldump参数分析


    mysqldump重要参数分析:

    -F, --flush-logs Flush logs file in server before starting dump. Note that
    if you dump many databases at once (using the option
    --databases= or --all-databases), the logs will be
    flushed for each database dumped. The exception is when
    using --lock-all-tables or --master-data: in this case
    the logs will be flushed only once, corresponding to the
    moment all tables are locked. So if you want your dump
    and the log flush to happen at the same exact moment you
    should use --lock-all-tables or --master-data with
    --flush-logs.

    —使用此参数会在导出前刷新日志文件,如果导出多个库,则在每个库导出前都会刷新一次日志;例外的是如果用了 --lock-all-tables or --master-data,则仅会刷新一次日志,对应此时刻所有表都会被锁上。

    --master-data[=#] This causes the binary log position and filename to be
    appended to the output. If equal to 1, will print it as a
    CHANGE MASTER command; if equal to 2, that command will
    be prefixed with a comment symbol. This option will turn
    --lock-all-tables on, unless --single-transaction is
    specified too (in which case a global read lock is only
    taken a short time at the beginning of the dump; don't
    forget to read about --single-transaction below). In all
    cases, any action on logs will happen at the exact moment
    of the dump. Option automatically turns --lock-tables
    off.

    —此参数为1时dump文件中有包含change master命令,若为2则change master语句是注释掉的;
    此参数会自动触发–lock-all-tables启动,除非同时使用了–single-transaction;
    即如果–master-data和–single-transaction同时使用的情况下,–lock-all-tables是不会被触发启动的,此时在dump开始的很短一段时间会有一个全局的读锁,因为–single-transaction就是会触发全局读锁。
    在任何情况下,使用–master-data都会触发–lock-tables关闭。

    --set-gtid-purged[=name]
    Add 'SET @@GLOBAL.GTID_PURGED' to the output. Possible
    values for this option are ON, OFF and AUTO. If ON is
    used and GTIDs are not enabled on the server, an error is
    generated. If OFF is used, this option does nothing. If
    AUTO is used and GTIDs are enabled on the server, 'SET
    @@GLOBAL.GTID_PURGED' is added to the output. If GTIDs
    are disabled, AUTO does nothing. If no value is supplied
    then the default (AUTO) value will be considered.

    --single-transaction
    Creates a consistent snapshot by dumping all tables in a
    single transaction. Works ONLY for tables stored in
    storage engines which support multiversioning (currently
    only InnoDB does); the dump is NOT guaranteed to be
    consistent for other storage engines. While a
    --single-transaction dump is in process, to ensure a
    valid dump file (correct table contents and binary log
    position), no other connection should use the following
    statements: ALTER TABLE, DROP TABLE, RENAME TABLE,
    TRUNCATE TABLE, as consistent snapshot is not isolated
    from them. Option automatically turns off --lock-tables.

    —使用此参数在一个单事务中创建一个一致性快照,目前只对InnoDB有效。当使用此参数进行备份时,确保没有其它的DDL语句执行,因为一致性读并不能隔离DDL语句。
    此参数自动触发–lock-tables关闭。

    -x, --lock-all-tables
    Locks all tables across all databases. This is achieved
    by taking a global read lock for the duration of the
    whole dump. Automatically turns --single-transaction and
    --lock-tables off.

    —对所有架构中的所有表上锁,则存在问题:是否锁的时间会更长?生产环境适用吗?

    -l, --lock-tables Lock all tables for read.
    (Defaults to on; use --skip-lock-tables to disable.)

    —此参数在备份过程中依次锁住每个架构下的所有表,一般用于MyISAM引擎,当备份时只能对数据库进行读取操作,不过依然可以保证备份的一致性。
    对于InnoDB引擎,不需要使用此参数,用–single-transaction即可,并且–lock-tables和–single-transaction是互斥的,不能同时使用,若同时使用了,则–single-transaction会触发–lock-tables关闭。
    如果同时备份InnoDB和MyISAM引擎,则只能使用–lock-tables了,–lock-tables只能保证每个架构下的表备份的一致性,不能保证所有架构下的表一致性。(问:那是否用–lock-all-tables就好了?)

  • 相关阅读:
    野路子码农系列(7)近期花里胡哨技巧汇总
    野路子码农系列(6)有关线下验证集选取的思考
    野路子码农(5)Python中的装饰器,可能是最通俗的解说
    野路子码农(4)挖掘机云端部署小试
    野路子码农系列(3)plotly可视化的简单套路
    野路子码农系列(2)Python中的类,可能是最通俗的解说
    野路子码农系列(1) 创建Web API
    pandas技巧两则——列内元素统计和列内元素排序
    Windows环境下Anaconda安装TensorFlow的避坑指南
    让米帝领事馆给你报空气质量(动态网页爬取及简单的数据整理)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13284402.html
Copyright © 2020-2023  润新知