开发者

mysqldump with where clause using referential integrity

I know I can dump a single table using the "where clause" but I was wondering if its possible to dump a table and have all the linking records be dumped along with them if they belong to a certain account id?

All my tables are innodb and have been set up using foreign key 开发者_开发问答constraints with cascade delete. If I delete the main table "account" where account_id = 1 then all the records that link to account_id of "1" will also be deleted.

So what I want is something similar in concept. I want to dump all the data for "Account_id=1" in all the tables that link to the "account" table in one command. If I do the following command I believe it will only dump the one table:

mysqldump -t -u [username] -p test account --where="account_id = 1"

Is there another way to dump on table with a where clause and automatically dump the data in liking tables without having to write separate dump commands for each table? ultimately I want to end up with a .sql file for each account like "account_1.sql", account_2.sql, etc.


I had put this question in my favorite list to see if someone comes with an idea, and as I was expecting no one did.

One rather funny way is to clone the DB, delete all not-required account ids (delete will cascade to all tables) and then dump the remaining (which will be all the account ids you require).

I was running through the same issue with MySQL, and DBIx::Class (an ORM in Perl). What I wanted to do was to clone a thousand of accounts (with obfuscated names and emails). I ended up writing a script to traverse the whole database through the foreign keys of a given user id and generate all the required insert statements in proper order.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜