建表
drop table if exists t1;
CREATE TABLE t1(
id int NOT NULL AUTO_INCREMENT PRIMARY KEY comment '主键',
person_id tinyint not null comment '用户id',
person_name varchar(30) comment '用户名称',
gmt_create datetime not null comment '创建时间',
gmt_modified datetime comment '修改时间'
) comment '测试表2048条';
插入一条数据
insert into t1 values(1,1,'user_1', NOW(), now());
写个脚本
DELIMITER //
CREATE PROCEDURE create_line(IN count INT)
BEGIN
DECLARE current_count INT;
SET current_count = 1;
WHILE current_count<=count DO
insert into t1(id, person_id, person_name, gmt_create, gmt_modified)
select @i:=@i+1,
left(rand()*10,1) as person_id,
concat('user_',@i%2048),
date_add(gmt_create,interval + @i*cast(rand()*100 as signed) SECOND),
date_add(date_add(gmt_modified,interval +@i*cast(rand()*100 as signed) SECOND), interval + cast(rand()*1000000 as signed) SECOND)
from t1;
SET current_count := current_count + 1;
END WHILE ;
END;
//
DELIMITER ;
执行脚本
SET @i = 1;
SET @count=3;
CALL create_line(@count);
附:
很多复杂业务的数据,通过这种sql的方式是无法实现的。可以用jmeter或者测试代码的方式。
网友评论