标签:mysql 导入数据 load data infile
1. 背景
导入150w数据到mysql,数据格式为tab分隔csv文件。测试索引对导入速度的影响
2. 无索引,导入数据后重建
CREATE TABLE `tab` ( `ct_id` char(36) DEFAULT NULL COMMENT ‘id‘, `ct_title` varchar(200) DEFAULT NULL COMMENT ‘标题‘, `bd_id` int(11) DEFAULT NULL COMMENT ‘bdid‘, `org_unit` int(11) DEFAULT NULL COMMENT ‘‘, `poi_id` int(11) DEFAULT NULL, `poi_name` varchar(200) DEFAULT NULL COMMENT ‘poi名称‘ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
mysql > load data infile ‘/tmp/ct.txt‘ into table tab; Query OK, 1928611 rows affected (15.83 sec) Records: 1928611 Deleted: 0 Skipped: 0 Warnings: 0
重建索引
mysql > alter table tab add UNIQUE index `uk_ct_poi` (`ct_id`,`poi_id`),
-> add index `idx_orgunit` (`org_unit`),
-> add index `idx_poi_orgunit` (`poi_id`,`org_unit`),
-> add index idx_bd_id(bd_id),
-> add index idx_poi_id(poi_id),
-> add index idx_poi_name(poi_name),
-> add index idx_all(ct_id,ct_title,bd_id,org_unit,poi_name),
-> add index idx_test(ct_title,bd_id,org_unit,poi_name);
Query OK, 0 rows affected (1 min 24.56 sec)
Records: 0 Duplicates: 0 Warnings: 0
3. 表建好索引导入数据
mysql > CREATE TABLE `tab` ( -> `ct_id` char(36) DEFAULT NULL COMMENT ‘id‘, -> `ct_title` varchar(200) DEFAULT NULL COMMENT ‘标题‘, -> `bd_id` int(11) DEFAULT NULL COMMENT ‘id‘, -> `org_unit` int(11) DEFAULT NULL COMMENT ‘‘, -> `poi_id` int(11) DEFAULT NULL, -> `poi_name` varchar(200) DEFAULT NULL COMMENT ‘poi名称‘, -> UNIQUE KEY `uk_ct_poi` (`ct_id`,`poi_id`), -> KEY `idx_orgunit` (`org_unit`), -> KEY `idx_poi_orgunit` (`poi_id`,`org_unit`), -> key idx_bd_id(bd_id), -> key idx_poi_id(poi_id), -> key idx_poi_name(poi_name), -> key idx_all(ct_id,ct_title,bd_id,org_unit,poi_name), -> key idx_test(ct_title,bd_id,org_unit,poi_name) -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
mysql > load data infile ‘/tmp/ct.txt‘ into table mixed_poi_mt_ct; Query OK, 1928611 rows affected (13 min 8.88 sec) Records: 1928611 Deleted: 0 Skipped: 0 Warnings: 0
4. 结论
大数据导入导出先导入数据再重建索引
标签:mysql 导入数据 load data infile
原文地址:http://yingtju.blog.51cto.com/3760152/1722425