Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
997 views
in Technique[技术] by (71.8m points)

mysql - mysqldump with multiple tables with or without where clause

I have a set of tables in my database that I have to take a dump ( :D ) of. My problem is I want to take some data from some tables that only date back certain days and would like to keep the remaining tables in tact.

The query I came up with was something like:

mysqldump -h<hostname> -u<username> -p <databasename> 
<table1> <table2> <table3> 
<table4> --where 'created > DATE_SUB(now(), INTERVAL 7 DAY)',
<table5> --where 'created > DATE_SUB(now(), INTERVAL 7 DAY)
--single-transaction --no-create-info | gzip
> $(date +%Y-%m-%d-%H)-dump.sql.gz

The trouble with the above code is that table1, table2 and table3 will try to take the where clause of table4. I don't want that cause that would spit out an error that created field does not exist in these tables.

I tried putting comma (,) after table names as I did after where clause but it doesn't work.

At this point I'm pretty much stuck and have no more alternative expect create two different sql dump files, which I wouldn't want to do.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

make two dumps or if you dont want to make two dumps then try two command

a.

mysqldump -h<hostname> -u<username> -p 
<databasename>  <table1> <table2> <table3>
--single-transaction --no-create-info > dumpfile.sql

b.

mysqldump -h<hostname> -u<username> -p <databasename> 
<table4> --where 'created > DATE_SUB(now(), INTERVAL 7 DAY)',
<table5> --where 'created > DATE_SUB(now(), INTERVAL 7 DAY)
--single-transaction --no-create-info >> dumpfile.sql

c.

gzip dumpfile.sql

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...