How to speed up a data loading into InnoDB (LOAD DATA INFILE)?
Asked Answered
P

5

7

I want to speed up a data loading.

I use MySQL 5.5, InnoDB and have 1M rows of data (65Mb file). It takes 5 minutes.

What mysql settings and commands affect the speed of LOAD DATA INFILE for InnoDB?

Thank you.

Phosphoresce answered 16/2, 2011 at 19:12 Comment(0)
I
21

I can recommend these settings to improve load time:

  • innodb_doublewrite = 0
  • innodb_support_xa = 0
  • innodb_buffer_pool_size = (50-80% of system memory)
  • innodb_log_file_size = (a large number - 256M etc)
  • innodb_flush_log_at_trx_commit = 0

Other than settings, there are some things you can do yourself:

  • Create indexes after loading (this is a new optimization with 5.5 / InnoDB plugin).
  • Sort the data file before loading.
  • Split the data file, and load in parallel.
Isaak answered 19/2, 2011 at 20:30 Comment(0)
C
5

Try removing indexes and triggers. You can re-create them after the load. Also look into using some of the high-load settings in my-huge.cnf instead of the defaults.

Some more innodb performance settings:

http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/

Caramelize answered 16/2, 2011 at 19:16 Comment(0)
B
2

This might not be exactly what you're looking for but is a trick I've used in the past

ALTER TABLE TABLE_NAME DISABLE KEYS;
LOAD DATA INFILE ... ;
ALTER TABLE TABLE_NAME ENABLE KEYS;

Hope it helps.

Bonnett answered 16/2, 2011 at 19:25 Comment(1)
This strategy works for MyISAM, not InnoDB.Opuntia
M
0

Also make sure that binary logging disabled if possible.

Melanesian answered 16/1, 2015 at 18:30 Comment(0)
A
-1

If you are in a hurry because you are replacing the contents of a live table, then do it this way instead:

CREATE TABLE new LIKE live;
LOAD DATA ... INTO new;
RENAME TABLE live TO old, new TO live;
DROP TABLE old;

The RENAME is 'instantaneous' and atomic, so you are 'never' down, regardless of table size.

(Hence you don't need to worry so much about speeding up the LOAD.)

Abhorrence answered 5/12, 2015 at 0:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.