First, some basic benchmarks. Multi-row Inserts are much quicker than single-row Insert syntax; Load Data Infile is much quicker than either. On a modern machine properly configured, you might insert 200-byte InnoDB rows at a rate of 2k rows/sec with single committed Inserts, six times that rate with multi-row Insert syntax and one Commit, three times that rate again with Load Data Infile.
Import performance also depends on source and target characteristics, for example with 30-300MB dump files of extended inserts into InnoDB tables, 350k-4 million row data rows in 800-4,000 statements, we see these speed ranges on modest 2020 hardware ... +------------+-----------+----------+--------+ | Source | Target | Rows/sec | MB/sec | +------------+-----------+----------+--------+ | local file | local SSD | 25-40k | 3-4 | +------------+-----------+----------+--------+ | local file | local HDD | 20k | 2 | +------------+-----------+---------+---------+ | local file | LAN HDD | 10k | 1 | +------------+-----------+----------+--------+MyISAM has no transaction logic so it's 20-25 times faster than InnoDB loading huge input files into a table. If bulk inserts into InnoDB tables can't be avoided, there's wide agreement that performance is improved by disabling For huge Inserts on a system with lots of RAM and multiple cores, in my.cnf try ... [mysqld] # leave core optimisation to mysql innodb_thread_concurrency = 0 innodb_read_io_threads = 64 innodb_write_io_threads = 64 innodb_io_capacity = 5000 Turning off set session sql_log_bin=0; See here for Bill Karwin's excellent slideshow on optimising InnoDB bulk inserts. For my.cnf settings that improve Insert performance, see https://nbsoftsolutions.com/blog/optimizing-innodb-bulk-insert It's often best to leave But be sure to read Kristian Köhntopp's excellent little note on keeping a disposable MySQL instance for speedy non-ACID bulk operations. On partitioning and InnoDB and Load Data, see http://www.ajaydivakaran.com/mysql-innodb-are-inserts-slowing-down, and on the benefits of chunking, see Baron Schwarz's pt-fifo_split. Last updated 2 Sep 2024 |
![]() |