MySQL使用存储过程插入千万级数据

来源:互联网 发布:ubuntu安装中文输入法 编辑:程序博客网 时间:2024/06/03 15:20
SET AUTOCOMMIT = 0;
delimiter $
//存储过程的方法名称
create procedure test() 
begin 
declare i decimal (10) default 0 ; 
dd:loop 
//插入语句
INSERT INTO `dn`.`news` (`id`, `title`, `img_url`, `content`) VALUES (NULL, '11111', 'fdsfsdffg.jpg', 'dfasdfasdfwetweyfsadfsadfsdfsdfdsfsdf');
commit; 
set i = i+1; 
//10000000是插入数据的数量
if i= 10000000 then leave dd; 
end if; 
end loop dd ; 
end;$ 
delimiter ; 
SET AUTOCOMMIT = 1;


新建一个SQL查询在里面执行call test();