mysqldump整个结构,但在单个命令中仅包含来自选定表的数据 [英] mysqldump entire structure but only data from selected tables in a single command
问题描述
我的数据库有3个表:table1,table2和table3
My database has 3 tables: table1, table2 and table3
我想在以下条件下对此数据库执行mysqldump:
I would like to do a mysqldump on this database with the following conditions:
- 所有表的转储结构
- 仅转储表1和表2的数据,忽略表3中的数据
目前,我使用2条mysqldump语句
Currently, I do this with 2 mysqldump statements
mysqldump -u user -p -d db > db_structure.sql
mysqldump -u user -p db --ignore-table=db.table3 > table1_and_table2_data.sql
以转储的相同顺序导入它们(结构,然后是表1和表2中的数据)
Import them in the same order they were dumped (structure, then data from table1 and table2)
是否可以将其组合为单个mysqldump命令?
Is there a way to combine this into a single mysqldump command?
推荐答案
您不能将它们合并为一个命令,但是可以同时执行两个命令并输出到同一文件.
You can't combine them in one command but you can execute both commands at the same time and output to the same file.
mysqldump -u user -p --no-data db > structure.sql; mysqldump -u user -p db table1 table2 >> structure.sql
为避免两次输入密码,您可以执行-ppassword
(注意空间有限!).也可以在第一个命令中使用--no-data
,否则也会得到数据.当您只处理一个数据库时,不需要-d.
to avoid having to enter the password twice you can do -ppassword
(note the lack of space!). Also use --no-data
in the first command or you end up with the data as well. -d isn't needed when you're doing just one database.
这篇关于mysqldump整个结构,但在单个命令中仅包含来自选定表的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!