两张表字段完全相同,一张 InnoDB,一张 MyISAM。
CREATE TABLE `user_sys` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(30) NOT NULL,
`user_pwd` varchar(30) NOT NULL,
`user_regdate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `user_sys2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(30) NOT NULL,
`user_pwd` varchar(30) NOT NULL,
`user_regdate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
灌入数据的存储过程 initdb
CREATE DEFINER=`root`@`localhost` PROCEDURE `initdb`(IN t int)
BEGIN
set @num=1;
while @num<1000001 do
if t=1 THEN
insert into user_sys (user_name,user_pwd) values(CONCAT('user',@num),'123');
ELSE
insert into user_sys2 (user_name,user_pwd) values(CONCAT('user',@num),'123');
END IF;
set @num=@num+1;
end while;
END
InnoDB 灌入一百万数据花费 132s,MyISAM 灌入一百万数据花费 40s。
call initdb(1);
-- 132s
call initdb(2);
-- 40s
select count(*) from user_sys;
-- 162ms
select count(*) from user_sys2;
-- 0.3ms
本文分享 CSDN - SugarPPig。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。