Duplicate all rows in a MySQL table
There are times where you need dummy data. And there are times where you need a lot of dummy data. I found a nice service called Mockaroo with which you can generate useful dummy data. The free service is capped at 1.000 entries. If you don't need unique data, but just a lot of data, you can simply duplicate the entries in your database until you have enough of it.
To do this you can use the following queries:
CREATE TEMPORARY TABLE tmp SELECT * from table_name;
ALTER TABLE tmp DROP id;
INSERT INTO table_name SELECT 0, tmp.* FROM tmp;
DROP TABLE tmp;
For it to work the field id
should be auto_increment
. The trick here being that when you insert 0
or NULL
into such a field, it will be generated automatically.
Start with the 1.000 entries they provide, run those queries 10 times and you've got 1.024.000 in a few seconds.