Export a subset of data, from mysql production database, to make a test database I have a mysql production database, with multiple tables. Tables are related with foreign key constraints. I want to make a small test database, by collecting/exporting only a small subset of data from the whole database (i.e. from all tables), so that foreign key constraints are preserved in the data subset.

How can I do that?
I doubt that there's a cookie-cutter approach, but the way I did it in the past went roughly as follows:


Pick some critical tables that must be populated for proper testing, preferably which have many dependencies, e.g. OrderDetail.
Create a new database with the same schema except no foreign key enforcement.
Randomly pick some rows from the source database, e.g. top 50 ordered by something pseudo-random, and insert into the new database.
Get all rows that they depend on and insert into the new database.
Repeat until no more rows are inserted.
Turn foreign key enforcement on.


It's slow and has many manual steps, but it worked for me.