设为首页 加入收藏

TOP

MySQL 命令行工具之 mysqldump 深入研究(二)
2015-11-12 21:29:16 来源: 作者: 【 】 浏览:16
Tags:MySQL 命令 工具 mysqldump 深入 研究
able. To specify more than one table to ignore, use the directive multiple times,


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? once for each table.? Each table must be specified with both database and table names,


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? e.g.,? --ignore-table=database.table. (在导出数据库时,排除某个或者某几个表不导出)


5) 按照 where 条件导出:


? -w, --where='where_condition' Dump only selected records. Quotes are mandatory.


6)使用示例:


Dumping structure and contents of MySQL databases and tables.
Usage: mysqldump [OPTIONS] database [tables]
OR? ? ? mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR? ? ? mysqldump [OPTIONS] --all-databases [OPTIONS]


1> 导出单表的结构和数据:mysqldump -uxxx -p db1 tb1 > tb1.sql; 导出数据库 db1 中的 表 tb1 的表结构 和 表中数据;


2> 导出多表的结构和数据:mysqldump -uxxx -p db1 tb1 tb2 > tb1_tb2.sql; 导出数据库 db1 中的 表 tb1、tb2 的表结构 和 表中数据;


3> 导出单表的结构:mysqldump -uxxx -p --no-data db1 tb1 > tb1.sql; 导出数据库 db1 中的 表 tb1 的表结构; 其实也可以使用: show create table tb1


4> 我们无法使用 mysqldump 到达 只导出某个或某几个表的数据,而不导出建表语句的目的。


? ? 但是我们可以使用 select * from table into outfile 'file.sql', 比如:select * from Users into outfile '/tmp/Users.sql'; 注意需要对目录的写权限。


5> 导出单个库中库结构、表结构、表数据:mysqldump -uxxx -p --databases db1 > db1.sql


6> 导出多个库中库结构、表结构、表数据:mysqldump -uxxx -p --databases db1 db2 > db1_db2.sql


7> 导出单个库中库结构、表结构、不要表数据:mysqldump -uxxx -p --no-data --databases db1 > db1.sql


8> 导出单个库中数据,不要库结构和表结构:mysqldump -uxxx -p --no-create-db --no-create-info --databases db1 > db1.sql


9> 导出多个库中库结构、表结构、不要表数据:mysqldump -uxxx -p?--no-data --databases db1 db2 > db1_db2.sql


10> 导出数据库中所有 库 的库结构,表结构,数据:mysqldump -uxxx -p --all-databases > all.sql


11> 导出数据库中所有 库 的库结构,表结构,不要数据:mysqldump -uxxx -p --all-databases?--no-data > all.sql


12> 导出单个库中库结构、表结构、表数据,排除某个表:mysqldump -uxxx -p --databases db1 --ignore-table=db1.test > db1.sql


4. mysqldump 事务 和 数据一致性(锁) 的相关选项


在使用mysqldump逻辑备份时,事务和数据一致性的选项时至关重要的。


1) --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.


? ? --single-transaction 可以得到一致性的导出结果。他是通过将导出行为放入一个事务中达到目的的。


? ? 它有一些要求:只能是 innodb 引擎;导出的过程中,不能有任何人执行 alter table, drop table, rename table, truncate table等DDL语句


? ? --single-transaction 会自动关闭 --lock-tables 选项;上面我们说到mysqldump默认会打开了--lock-tables,它会在导出过程中锁定所有表。


? ? 因为 --single-transaction 会自动关闭--lock-tables,所以单独使用--single-transaction是不会使用锁的。与 --master-data 合用才有锁。


2)--lock-tables


? ? 该选项默认打开的,上面已经说到了。它的作用是在导出过程中锁定所有表。--single-transaction 和?--lock-all-tables 都会将该选项关闭。


3)--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. 启用该选项,会自动关闭 --single-transaction 和 --lock-tables.


上面三个选项中,只有 --lock-tables 默认是打开的;打开 --single-transaction 或者 打开 --lock-all-tables 都将关闭 --lock-tables. 而--lock-all-tables会自动关闭 --single-transaction 和 --lock-tables。所以三者是互斥的。我们应该一次只启用其中一个选项。


4)--flush-logs? ?


? ? ? ? Flush logs file in server before starting dump. No

首页 上一页 1 2 3 4 5 下一页 尾页 2/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇数据处理之PostgreSQL过程语言学习 下一篇mysqldump 逻辑备份的正确方法

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: