0
create table foo (id, val1, user_id,...)
create table bar (id, foo_id, val2, ...)
create table baz (id, bar_id, val3, ...)

select * from foo where user_id = 1;
select * from bar where id in (select id from foo where user_id = 1)
select * from baz where id in (for all the above bars)

如何编写执行上述操作的转储命令

4

1 回答 1

2
mysqldump -h yourhost -u username -p yourDatabase foo --where="user_id = 1" >dumpFile1
mysqldump -h yourhost -u username -p yourDatabase bar --where=" id in (select id from foo where user_id = 1)" >dumpFile2
mysqldump -h yourhost -u username -p yourDatabase baz --where="id in (select * from bar where id in (select id from foo where user_id = 1))" >dumpFile3

另一种选择是导出为 CSV 文件。

select * from foo where user_id = 1 INTO OUTFILE 'C:/whatever'

或类似的东西。看看手册

更新:

没有测试,但你可以试试这个吗?

mysqldump -h yourhost -u username -p yourDatabase foo bar baz
--where="foo.user_id = 1" 
--where="bar.id in (select id from foo where user_id = 1)" 
--where="baz.id in (select * from bar where id in (select id from foo where user_id = 1))" 
>dumpFile

更新 2:

在 mysqldump 的手册中,我看不到多个 WHERE 子句。所以恐怕你必须分多个步骤来做。

于 2013-03-01T11:07:25.657 回答