MySQL 如何在mysql中导出多表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5189303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to export multi table in mysql?
提问by shanqn
i have 10+ tables, i want to export them to another datebase. how could i do that? i tried select * from table_a, table_b into ourfile "/tmp/tmp.data", but it joined the two tables.
我有 10 多个表,我想将它们导出到另一个数据库。我怎么能那样做?我尝试 select * from table_a, table_b 到我们的文件“/tmp/tmp.data”中,但它加入了两个表。
回答by Francisco QV
It's probably too late, but for the record:
可能为时已晚,但为了记录:
Export an entire database:
导出整个数据库:
mysqldump -u user -p database_name > filename.sql
Export only one table of the database:
仅导出数据库的一张表:
mysqldump -u user -p database_name table_name > filename.sql
Export multiple tables of the database
导出数据库的多张表
Just like exporting one table, but keep on writing table names after the first table name (with one space between each name). Example exporting 3 tables:
就像导出一个表一样,但是在第一个表名之后继续写表名(每个名称之间有一个空格)。导出 3 个表的示例:
mysqldump -u user -p database_name table_1 table_2 table_3 > filename.sql
Notes:
笔记:
The tables are exported (i.e. written in the file) in the order in which they are written down in the command.
表格按照在命令中写入的顺序导出(即写入文件)。
All of the examples above export the structure and the data of the database or table. To export only the structure, use no-data
. Example exporting only one table of the database, but with no-data:
上面的所有示例都导出了数据库或表的结构和数据。要仅导出结构,请使用no-data
. 仅导出数据库的一张表但没有数据的示例:
mysqldump -u user -p --no-data database_name table_name > filename.sql
回答by Zepplock
Export mysqldump -u user -p mydatabasename > filename.sql
出口 mysqldump -u user -p mydatabasename > filename.sql
Import mysql -u user -p anotherdatabase < filename.sql
进口 mysql -u user -p anotherdatabase < filename.sql