步骤:
1 创建数据表(MYISAM方式存储插入速度比innodb方式快很多)
数据表描述
数据量:1千万
字段类型:
id :编号
user_name :用户名
mobile:手机号
password : 密码
email : 邮箱
add_time : 创建时间
update_time : 更新时间
执行以下SQL命令:
CREATE TABLE user(
id serial,
user_name varchar(32) ,
mobile char(11) ,
password varchar(64) ,
email varchar(64) ,
add_time datetime ,
update_time datetime
)
ENGINE=MYISAM
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
AUTO_INCREMENT=1
ROW_FORMAT=COMPACT;
2 创建插入数据存储过程
执行以下SQL命令:
delimiter $$
SET AUTOCOMMIT = 0$$
create procedure test11()
begin
declare v_cnt decimal (10) default 0 ;
dd:loop
insert into user values
(null,'用户1','18338299767','','[email protected]','2020-12-1 00:00:00',''),
(null,'用户2','18338299767','','[email protected]','2020-12-1 00:00:00',''),
(null,'用户3','18338299767','','[email protected]','2020-12-1 00:00:00',''),
(null,'用户4','18338299767','','[email protected]','2020-12-1 00:00:00',''),
(null,'用户5','18338299767','','[email protected]','2020-12-1 00:00:00',''),
(null,'用户6','18338299767','','[email protected]','2020-12-1 00:00:00',''),
(null,'用户7','18338299767','','[email protected]','2020-12-1 00:00:00',''),
(null,'用户8','18338299767','','[email protected]','2020-12-1 00:00:00',''),
(null,'用户9','18338299767','','[email protected]','2020-12-1 00:00:00',''),
(null,'用户0','18338299767','','[email protected]','2020-12-1 00:00:00','')
;
commit;
set v_cnt = v_cnt+10 ;
if v_cnt = 10000000 then leave dd;
end if;
end loop dd ;
end;$$
delimiter ;
3 执行存储过程
执行以下SQL命令:
call test11;
耗时:试自己电脑配置而定(百十秒左右)
4 根据需要修改engineer (非必要步骤,如果不需要转换无需操作)
执行以下SQL命令:
alter table user engine=innodb;
耗时:试自己电脑配置而定(一两百秒左右)