0
点赞
收藏
分享

微信扫一扫

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

Ichjns 2022-08-02 阅读 104


[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中使用该参数


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

[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.备份单库

[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

举报

相关推荐

0 条评论