最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

关于mysql使用存储过程插入大量数据的问题

来源:懂视网 责编:小采 时间:2020-11-09 16:36:22
文档

关于mysql使用存储过程插入大量数据的问题

关于mysql使用存储过程插入大量数据的问题:mysql大量数据插入存储过程 创建数据库create database ceshi;use ceshi;创建表create table ce(id int not null auto_increment,name varchar(50) default null,pw char(50),primary key(id));存储过程del
推荐度:
导读关于mysql使用存储过程插入大量数据的问题:mysql大量数据插入存储过程 创建数据库create database ceshi;use ceshi;创建表create table ce(id int not null auto_increment,name varchar(50) default null,pw char(50),primary key(id));存储过程del

mysql大量数据插入存储过程

创建数据库
create database ceshi;
use ceshi;
创建表
create table ce(
id int not null auto_increment,
name varchar(50) default null,
pw char(50),
primary key(id));

存储过程
delimiter //
create procedure insert_ce(in item int)
begin
declare counter int;
declare i int;
set counter=item;
while counter >=1 do
insert into ce values(counter,concat('mysqls',counter),repeat('ab',5));
set counter =counter-1;
set i=i+1;
if i=1000 then
set i=0;
commit;
end if;
end while;
end
//
delimiter ;
十万条数据使用的时间是40分钟

另一钟方法:
create table t_2 (id serial,name char(5)) ;
delimiter $$
SET AUTOCOMMIT = 0$$

create procedure test02(in i int)
begin
declare v_cnt decimal (10) default 0 ;
dd:loop
insert into t_2 values
(null,'aaaaa'),
(null,'aaaaa'),
(null,'aaaaa'),
(null,'aaaaa'),
(null,'aaaaa'),
(null,'aaaaa'),
(null,'aaaaa'),
(null,'aaaaa'),
(null,'aaaaa'),
(null,'aaaaa');
commit;
set v_cnt = v_cnt+10 ;
if v_cnt = i then leave dd;
end if;
end loop dd ;
end;$$

delimiter ;
十万条数据使用的时间是7分钟
设置缓存的话不到两种方法都是一份钟不到就好了,朋友说有可能是默认缓存过小的原因。可是,两种方法在同一个机子上测试,没有设置缓存,所用的时间就是差很多。
想问一下是什么原因造成的,还想知道插入多少条数据提交一次才是最优插入,第二种方法的注释?

文档

关于mysql使用存储过程插入大量数据的问题

关于mysql使用存储过程插入大量数据的问题:mysql大量数据插入存储过程 创建数据库create database ceshi;use ceshi;创建表create table ce(id int not null auto_increment,name varchar(50) default null,pw char(50),primary key(id));存储过程del
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top