How to Seed MySQL with Realistic Test Data
The Problem
MySQL powers millions of applications, but seeding a development database with realistic data is still surprisingly painful. Most developers resort to copying subsets of production (a compliance nightmare) or writing INSERT statements with placeholder values that tell you nothing about how the application will actually behave.
ORMs like Sequelize or TypeORM have seed features, but you still have to supply the data. Foreign key constraints mean you have to insert tables in the right order with matching IDs.
The Solution: MockHero API
MockHero generates realistic, relational test data from a simple JSON schema. Request format: "sql" and pipe the output directly into the mysql CLI, or use JSON with your ORM of choice.
Quick Setup
curl -X POST https://api.mockhero.dev/api/v1/generate \
-H "x-api-key: mh_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"tables": [
{
"name": "categories",
"count": 8,
"fields": [
{ "name": "id", "type": "auto_increment" },
{ "name": "name", "type": "word" },
{ "name": "description", "type": "sentence" }
]
},
{
"name": "products",
"count": 50,
"fields": [
{ "name": "id", "type": "auto_increment" },
{ "name": "category_id", "type": "ref", "params": { "ref": "categories.id" } },
{ "name": "name", "type": "product_name" },
{ "name": "price", "type": "decimal", "params": { "min": 5, "max": 500 } },
{ "name": "sku", "type": "uuid" },
{ "name": "in_stock", "type": "boolean" }
]
}
],
"format": "sql"
}'
Step-by-Step Guide
1. Prerequisites
You need the mysql CLI client and curl.
2. Get your MockHero API key
Sign up at mockhero.dev/sign-up.
3. Create your tables
CREATE TABLE categories (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description TEXT
);
CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY,
category_id INT,
name VARCHAR(200) NOT NULL,
price DECIMAL(10,2) NOT NULL,
sku VARCHAR(50),
in_stock BOOLEAN DEFAULT TRUE,
FOREIGN KEY (category_id) REFERENCES categories(id)
);
4. Generate and insert
Use the curl command above. The SQL output includes properly ordered INSERT statements that respect foreign keys.
5. Verify
mysql -u root -p mydb -e "SELECT p.name, p.price, c.name AS category FROM products p JOIN categories c ON c.id = p.category_id LIMIT 5;"
Complete Example
Save the curl command as seed.sh for repeatable seeding. The SQL output handles insert ordering so foreign key constraints are always satisfied.
Why MockHero vs Faker / Manual Seeds
- Pipe and done — SQL output goes straight into
mysqlCLI, no code needed. - Auto-ordered inserts — parent tables are inserted before children automatically.
- MySQL-compatible types —
auto_increment,decimal, andbooleanmap natively.
Get Started
Free tier, no credit card. Sign up at mockhero.dev and seed your MySQL database in one command.
MockHero Team
Guides and tutorials for generating realistic test data with the MockHero API.
Start generating test data for free
1,000 rows/month on the free tier. No credit card required.
Get Your API Key