Mysqldump tables from different databases?

I want to backup two tables: table1 and table2 .

table1 from database database1 .

table2 from database database2 .

Is there a way to reset them with a single mysqldump call?

I know that I can:

mysqldump -S unixSocket --skip-comments --default-character-set=utf8 --databases database1 --tables table1 > /tmp/file.sql 

But how to dump two tables from different databases?

+4
source share
5 answers

Use mysqldump twice, but the second time with a redirect to a file, like append >> /tmp/file.sql .

+5
source

Syntax:

  mysqldump --databases db_name1 [db_name2 ...]> my_databases.sql

Check the link: http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

Hope this helps

+2
source

There are three general ways to call mysqldump:

 shell> mysqldump [options] db_name [tbl_name ...] shell> mysqldump [options] --databases db_name ... shell> mysqldump [options] --all-databases 

Only the first one allows you to select the name of the database and table, but not allow multiple databases. If you use the second or third option, you will delete the selected databases (second) or all databases (third).

So you can do this, but you need to reset all the databases.

As Michael Paugaga said in the comments, you can also do this twice.

first time with > /tmp/file.sql "

second time with " >> /tmp/file.sql to append "

+1
source

For linux / bash, oneliner:

(mysqldump dbname1 --tables table1; mysqldump dbname2 --tables table2) | gzip > dump.sql.gz

0
source

This may be a workaround, but you can ignore other tables that you DO NOT want to back up.

For example, in your case:

 mysqldump --databases database1 database2 --ignore-table=database1.table2 --ignore-table=database2.table1 

You need to define every table that you DO NOT want to flush with every -ignore-table statement.

Good luck

0
source

Source: https://habr.com/ru/post/1382501/


All Articles