How to create a database that is a randomized subset of another db (mysql)? I have a MySQL-DB containing 2 tables "records" and "features" linked by one foreign key in features referring to the primary key "id" in records.

My goal is to create a randomized but fixed subset of the data in the DB for machinelearning that can be dumped and hashed for reproducability.

So I thought it would be handy if I could draw a randomized subset of the data and move it to a seperate DB. 

Is that possible and if yes: how?
Add another column to the table.  It could be DOUBLE or INT or BIGINT, depending on size, etc.  Populate it with some function of RAND().  Also, index the column.

Now you can fetch rows that are consecutive in this new column; they will be "random" from the point of view of the original data.  And it will be reproducible.

SELECT * FROM tbl
    WHERE myrand &gt; $x
    ORDER BY myrand  LIMIT 200000;


In this case I am allowing $x to give you different subsets of the table -- each reproducible.  You would need to adjust $x to avoid overlapping between one subset and another (if that matters).

Note:  I did not copy the data over, merely fetched directly from the original data.  This may be an added benefit.  Or it simply gives you the way to 'copy' the rows.