签到成功

知道了

CNDBA社区CNDBA社区

mysqldump命令详解 --single-transaction参数的使用

2021-12-04 18:50 2762 0 原创 mysql
作者: hbhe0316
 [root@mysql57 data]# mysqldump --help
 --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.

该参数通过在一个事务中导出所有表从而创建一个一致性的快照,当前版本的MySQL只可以对innodb 引擎保证一致性,导出过程中不会锁表其他引擎,如MyISAM 在导出期间会锁表为保证有效的dump文件,即正确的表内容和二进制日志位置,在导出的过程中不能有如下操作
ALTER TABLE
DROP TABLE
RENAME TABLE
TRUNCATE TABLE
如指定了 —lock-tables参数则会自动将其关闭,推荐在mysqldump中使用该参数http://www.cndba.cn/hbhe0316/article/22701http://www.cndba.cn/hbhe0316/article/22701http://www.cndba.cn/hbhe0316/article/22701

使用—single-transaction备份数据库
1.备份全库

http://www.cndba.cn/hbhe0316/article/22701
http://www.cndba.cn/hbhe0316/article/22701http://www.cndba.cn/hbhe0316/article/22701

[root@mysql57 data]# mysqldump -h127.0.0.1 -uroot -pwwwwww --single-transaction --set-gtid-purged=OFF  --all-databases --master-data=2  --triggers --events --routines> /tmp/all_master.sqlmysqldump: [Warning] Using a password on the command line interface can be insecure.[root@mysql57 data]# du -sm /tmp/all_master.sql 
512     /tmp/all_master.sql

2.备份单库

http://www.cndba.cn/hbhe0316/article/22701
http://www.cndba.cn/hbhe0316/article/22701http://www.cndba.cn/hbhe0316/article/22701
http://www.cndba.cn/hbhe0316/article/22701

[root@mysql57 data]# mysqldump -h127.0.0.1 -uroot -pwwwwww --single-transaction --set-gtid-purged=OFF  --databases testdb  --master-data=2   --triggers --events --routines> /tmp/testdb_all_master.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.

版权声明:本文为博主原创文章,未经博主允许不得转载。

MYSQL

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
hbhe0316

hbhe0316

关注

1.只有承认无知,才能装下新的东西; 2.进步来自一点点滴滴的积累; 3.广博让你更优秀,而专业让你无法替代; 4.挫折和失败能够转换为一种财富。

  • 889
    原创
  • 1
    翻译
  • 13
    转载
  • 24
    评论
  • 访问:2645742次
  • 积分:1523
  • 等级:核心会员
  • 排名:第6名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ