0

Is there a way to populate (generate in an easy way) a dummy data in MySQL Workbench based on an existing database schema ?

I know I can select database, and click on "Select Rows - Limit 1000" and start inserting values for each row. But that would be rather long proces because of fairly complex database schema.

I guess there is something inside of MySQL Workbench to get around this, right?

Whirlwind
  • 14,286
  • 11
  • 68
  • 157

1 Answers1

1

There's a neat trick to quickly fill a table with dummy data (actually all duplicated rows).

Start with a normal insert query:

insert into table t1 values (value1, value2 ...);

That is your base record. Now do another insert with a select:

insert into table t1 select * from t1;

Now you have 2 records. Do the same query again for 4 records, again for 8, 16, 32 etc. Of course you have to take care not to insert duplicate keys (e.g. by trimming the select statement, or use an auto inc value without copying it or have no indices at all and add them later etc.).

In MySQL Workbench you can just duplicate this query 20 times in the editor (copy/paste) and run the entire editor content once to get 1 million rows.

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
  • Nice one, but, this wouldn't work for a whole database eg. for junction tables... But, you have my upvote because this might be useful in some cases. – Whirlwind May 22 '17 at 09:25