What mysql settings affect the speed of LOAD DATA INFILE?

怎甘沉沦 提交于 2019-12-03 15:23:41

Inserting into indexes in general kills performance. You may be better off removing the index before inserting data and re-indexing after insertion.

From http://forum.percona.com/s/m/983/:

Normally MySQL is rather fast loading data in MyISAM table, but there is exception, which is when it can't rebuild indexes by sort but builds them row by row instead. It can be happening due to wrong configuration (ie too small myisam_max_sort_file_size or myisam_max_extra_sort_file_size) or it could be just lack of optimization, if you're having large (does not fit in memory) PRIMARY or UNIQUE indexes.

Also check out http://www.mysqlperformanceblog.com/2007/05/24/predicting-how-long-data-load-would-take/ and http://www.linuxtopia.org/online_books/database_guides/mysql_5.1_database_reference_guide/insert-speed.html.

I don't know about settings, but my money is on that composite primary key as to why you are having such poor performance.

If your Table is MyISam and if data is being added to a non empty table, bulk_insert_buffer_size matters

MyISAM uses a special tree-like cache to make bulk inserts faster for LOAD DATA INFILE when adding data to nonempty tables. The BULK_INSERT_BUFFER_SIZE variable limits the size of the cache tree in bytes per thread. Setting it to 0 disables this optimization. The default value is 8MB. The maximum value is 4GB.

If data is being added to a non-empty table, tuning the bulk_insert_buffer_size variable can make data insertion faster. Normally, it shows the improvement when the data to be inserted is more than 10k rows. But it is hard to say what is the right value, so, trail and try with incremental buffer size values.

Also, performance improvement will be more obvious if the following variables are also set:

  • MYISAM_SORT_BUFFER_SIZE
  • KEY_BUFFER_SIZE

You should also consider disabling the indexes before loading the data using the following alter table command:

alter table t disable keys;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!