最近发现了一个Mysql快速导入数据方法load data infile,具体参考http://www.taobaodba.com/html/558_loaddata.html,这个文章。
下面用几条命令来给大家看看,效率结果。
简单说下:
1.txt ,开始只有10万数据,后来用vim 添加到了2000万行,用Windows下的编辑器直接卡机的,Windows下安装Gvim可以的。
数据表类型Innodb,没做任何的索引优化。
1.导入10万行记录不到1秒
mysql> load data infile './1.txt' into table article (keywords);
Query OK, 107200 rows affected (0.96 sec)
Records: 107200  Deleted: 0  Skipped: 0  Warnings: 0
2.导入2000万行的数据量
mysql> load data infile './1.txt' into table article (
Query OK, 20000000 rows affected (5 min 53.02 sec)
Records: 20000000  Deleted: 0  Skipped: 0  Warnings: 0
3.在9000万中统计数据,注意和第四个对比
mysql> select count(id) from article ;
+-----------+
| count(id) |
+-----------+
|  92893775 |
+-----------+
1 row in set (1 min 28.86 sec)
4.查询1亿1千万的数据,比上一个明显的时间多了。
mysql> select count(id) from article ;
+-----------+
| count(id) |
+-----------+
| 112893775 |
+-----------+
1 row in set (5 min 18.83 sec)
5.用count(*)时间减少了25秒左右。
mysql> select count(*) from article ;
+-----------+
| count(*)  |
+-----------+
| 112893775 |
+-----------+
1 row in set (4 min 5.53 sec)
6.用count(1)直接节省1分40秒
mysql> select count(1) from article ;
+-----------+
| count(1)  |
+-----------+
| 112893775 |
+-----------+
1 row in set (3 min 36.59 sec)
2011年3月19日添加新的测试
MYISAM引擎


mysql> select count(1) from test;
+-----------+
| count(1)  |
+-----------+
| 326039962 |
+-----------+
1 row in set (0.08 sec)
过多的话,我不说了,大家看结果吧。
Logo

更多推荐