mysql生成海量测试数据

通过存储过程可以生成海量数据

-- 创建测试表
DROP TABLE t1;
CREATE TABLE t1(
  id INT unsigned NOT NULL AUTO_INCREMENT,
  name VARCHAR(20) NOT NULL,
  status TINYINT unsigned NOT NULL DEFAULT 1,
  PRIMARY KEY(id)
);

-- 添加数据
DROP PROCEDURE insert_t1;
DELIMITER //
CREATE PROCEDURE insert_t1()
BEGIN
  DECLARE num INT;
  SET num=1;
  SET autocommit=0;
  WHILE num < 10000000 DO
    IF (num%10000=0) THEN
      COMMIT;
    END IF;
    INSERT INTO t1 VALUES(NULL, 'XXXXXXXX', 1);
    SET num=num+1;
  END WHILE;
  COMMIT;
  SET autocommit=1;
END //

DELIMITER ;

CALL insert_t1();