Generating Test Data that Satisfies Foreign Key Relationships with mysql_random_data_load
This tutorial explains how to create a test database, define tables with foreign key constraints, populate them with appropriate random data using mysql_random_data_load, and work around a known bug that forces the foreign‑key sample size to 100 rows.
In Experiment 8 we generated test data for tables, and a reader asked how to handle random data when two tables have a foreign‑key relationship that the generated data cannot satisfy.
First, we create a test database and define two tables with a foreign‑key relationship. We then insert basic data into the office table, followed by data into the user table that references the foreign keys.
The resulting output shows that the tool correctly generates values for the office1 and office2 foreign‑key columns, with a sampling size of exactly 100 rows.
Tip: If you need different sample sizes for different foreign‑key columns, create multiple tables—each configured with a single foreign‑key column—and merge them into one table after generation.
Pitfall: In mysql_random_data_load version 0.1.12, the --max-fk-samples option does not take effect and always uses 100 samples. A temporary fix is available for download from the provided GitHub link while waiting for an official Percona fix.
Related articles and further reading links are listed at the end of the original page.
Aikesheng Open Source Community
The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.