3

mysql生成海量测试数据

 2 years ago
source link: https://www.80shihua.com/archives/2319
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

mysql生成海量测试数据

作者: dreamfly 分类: mysql 发布时间: 2020-04-07 15:50

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

-- 创建测试表
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();

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用*标注


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK