Fill database tables with a large amount of test data

后端 未结 7 1395
长发绾君心
长发绾君心 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条回答
  •  一向
    一向 (楼主)
    2020-12-07 09:59

    For multiple row cloning (data duplication) you could use

    DELIMITER $$
    CREATE PROCEDURE insert_test_data()
    BEGIN
      DECLARE i INT DEFAULT 1;
    
      WHILE i < 100000 DO
        INSERT INTO `table` (`user_id`, `page_id`, `name`, `description`, `created`)
        SELECT `user_id`, `page_id`, `name`, `description`, `created`
        FROM `table`
        WHERE id = 1;
        SET i = i + 1;
      END WHILE;
    END$$
    DELIMITER ;
    CALL insert_test_data();
    DROP PROCEDURE insert_test_data;
    

提交回复
热议问题