Mysql – Need to make MySQL’s LOAD DATA LOCAL INFILE load large data faster

innodbMySQL

I need to load 4 million rows of data into a MySQL InnoDB table using LOAD DATA INFILE and would like to know if there are server configuration options I can tweak to get faster load.

It took me 15 minutes to loaded 2 million rows, a performance I thought was disappointing for the LOAD DATA INFILE. My statement looks like this

LOAD DATA LOCAL INFILE 'path/file.csv'
INTO TABLE table FIELDS
TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES (column1, column2, etc);

Best Answer

Although LOAD DATA INFILE can work against InnoDB, there are too many ways InnoDB gets tapped to its limits before swapping and bottlenecks takeover.

Here is a Pictorial Representation of InnoDB (from Percona CTO Vadim Tkachenko)

InnoDB Plumbing

The bottlenecks would be goring through the following structures

  • InnoDB Buffer Pool
  • Transaction Logs (ib_lofile0, ib_logfile1)
  • Double Write Buffer
  • Insert Buffer
  • One Rollback Segment
  • Log Buffer

Here are some of my past posts where I discuss LOAD DATA INFILE with InnoDB

SUGGESTION #1

Break up the file into 20 smaller files.

Instead of one LOAD DATA INFILE against a 2 million row file, perform 20 LOAD DATA INFILE against 20 files, each with 100 thousand rows.

The Benefit : Less pressure against the InnoDB Plumbing

SUGGESTION #2 (Optional)