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)

上記を実行する dump コマンドの書き方

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

もう 1 つのオプションは、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 に答える