mysql 批量插入测试数据,两分钟插入10W条

CREATE PROCEDURE pro_cust_batch()
BEGIN
declare v_login_name BIGINT DEFAULT 13800000000;
declare v_max BIGINT DEFAULT 100000;
declare batch int default 50;
declare i int default 0;
declare v_pwd varchar(35);
declare v_img varchar(150);
declare v_groupId int;
declare v_regfrom varchar(10);
declare v_curdate datetime;
declare v_sqltext VARCHAR(9000);
declare v_firstSql VARCHAR(400);

set v_pwd=e10adc3949ba59abbe56e057f20f883e;
set v_img=Users/img/1.png;
set v_groupId=27;
set v_curdate=NOW();
set v_sqltext=;

WHILE i < v_max DO
set i = i + 1;
set v_login_name=v_login_name+1;
set v_regfrom=concat(PC,i);

set v_firstSql=concat((,v_login_name,,,v_pwd,,,v_img,,,v_login_name,,,v_curdate,,,v_groupId,,,v_regfrom,,,0,,,1,,,1,,,v_curdate,));
if mod(i,batch)=1 then
set v_sqltext=concat(v_firstSql);
else
set v_sqltext=concat(v_sqltext,,,v_firstSql);
end if;

if mod(i,batch)=0 then
set @sqltext=concat(INSERT INTO cus_customer(LoginName,Pwd,Uimage,Mobile,RegTime,GroupId,RegFrom,MaxOnline,State,CreateId,CreateTime) VALUES ,v_sqltext);
prepare stmt from @sqltext;
execute stmt;
DEALLOCATE PREPARE stmt;
set v_sqltext=;
end if;

END WHILE;

end
经验分享 程序员 微信小程序 职场和发展