Mysql – For MySQL, is there tool to dump a set of rows from one tables and all related (by foreign key) rows from all related tables

MySQLmysqldump

I'm using MySQL db.

I want to dump a set of rows from one table and if these rows have foriegn keys that point to rows on some other tables, I want to dump those too.

Then I want to load these dumps into their respective tables on a different database (e.g using LOAD DATA INFILE command). So simply using select...join...into outfile is not enough since the result would be one big joined table.

For example table A has B_id and C_id columns that point to rows on table B and C respectively. So when I dump 3 rows from table A, 3 related rows from B and 3 from C are dumped too.

Does such a tool/script exist?

Writing a script to do that is very doable, but I don't want to reinvent the wheel if such a tool already exist.

Best Answer

I think Jailer is what you are looking for:

http://jailer.sourceforge.net/

(Though I haven't used it so far)