Fill database tables with a large amount of test data

后端 未结 7 1412
长发绾君心
长发绾君心 2020-12-07 09:18

I need to load a table with a large amount of test data. This is to be used for testing performance and scaling.

How can I easily create 100,000 rows of random/junk

7条回答
  •  猫巷女王i
    2020-12-07 09:49

    If you want more control over the data, try something like this (in PHP):

    
    

    where function generate_test_values would return a string formatted like "('val1', 'val2', ...)". If this takes a long time, you can batch them so you're not making so many db calls, e.g.:

    for ($i = 0; $i < $num; $i += 10) {
      $values = array();
      for ($j = 0; $j < 10; $j++) {
        $values[] = generate_test_data($i + $j);
      }
      mysql_query($sql . join(", ", $values));
    }
    

    would only run 10000 queries, each adding 10 rows.

提交回复
热议问题