Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 748
Jean Louis Avatar asked Feb 16 '11 19:02

Jean Louis


People also ask

How can I speed up MySQL data loading?

if you're using innodb and bulk loading here are a few tips: sort your csv file into the primary key order of the target table : remember innodb uses clustered primary keys so it will load faster if it's sorted ! Disabling unique_checks already improved the performance, as well as sorting by primary key. Thanks!

What is load data infile?

The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed. If the LOCAL keyword is specified, the file is read from the client host. If LOCAL is not specified, the file must be located on the server. ( LOCAL is available in MySQL 3.22.

How does load data local infile work?

In contrast, when you execute the LOAD DATA LOCAL INFILE statement, the client attempts to read the input file from its file system, and it sends the contents of the input file to the MariaDB Server. This allows you to load files from the client's local file system into the database.

What is load file in MySQL?

MySQL LOAD_FILE() reads the file and returns the file contents as a string. Syntax: LOAD_FILE (file_name)


1 Answers

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.
like image 165
Morgan Tocker Avatar answered Feb 01 '23 16:02

Morgan Tocker