2

我加载文件的当前方式是:

   load data local infile 'file_name' into table tableA  
fields terminated by ',' enclosed by '"' lines terminated by '\n';

是在 unix 机器中加载表的最佳方式。它是否创建了最佳的表大小?我想要一张占用空间最小的桌子。

4

1 回答 1

2

MyISAM

如果表是 MyISAM,您应该执行以下操作:

set bulk_insert_buffer_size = 1024 * 1024 * 256;
alter table tableA disable keys;
load data local infile 'file_name' into table tableA  
fields terminated by ',' enclosed by '"' lines terminated by '\n';
alter table tableA enable keys;

InnoDB

如果表是 InnoDB,您应该执行以下操作:

set bulk_insert_buffer_size = 1024 * 1024 * 256;
load data local infile 'file_name' into table tableA  
fields terminated by ',' enclosed by '"' lines terminated by '\n';

这不仅会占用最少的空间(加载一个空表),而且这些行将根据bulk_insert_buffer_size缓存在内存中的树状结构中,以便在重新加载期间更快地缓存数据。

如果您担心 ibdata1 爆炸,则需要将所有 InnoDB 表转换为使用innodb_file_per_table。请使用我的 InnoDB 清理步骤:Howto: Clean a mysql InnoDB storage engine?

于 2012-06-04T23:02:54.653 回答