如何备份 mysql 数据库中的两个表?

how to take backup of two tables in the mysql database?

我知道 mysql转储实用程序,因为它需要备份整个数据库。我需要在 mysql 数据库中备份两个 table,其中一个 table 包含所有条目,第二个没有条目。而且我在一个 sql(即 mydb.sql)文件中需要两个 tables。

可能吗?

Mysqldump也可以转储单表,可选择带或不带数据:

mysqldump [options] db_name [tbl_name ...]

--no-data, -d: Do not write any table row information (that is, do not dump table contents).

因此要转储包含所有条目的 table1 和没有条目的 table2,您可以像这样调用 mysqldump 两次:

mysqldump db_name table1 > table1.sql
mysqldump --no-data db_name table2 > table2.sql

UPDATE:要将两个表转储到一个文件中,您可以将第二个命令的输出附加到第一个命令:

mysqldump db_name table1 > dump.sql
mysqldump --no-data db_name table2 >> dump.sql