For loading huge amounts of data into MySQL, LOAD DATA INFILE is by far the fastest option. Unfortunately, while this can be used in a way INSERT IGNORE or REPLACE works, ON DUPLICATE KEY UPDATE is not currently supported.
However, ON DUPLICATE KEY UPDATE
has advantages over REPLACE
. The latter does a delete and an insert when a duplicate exists. This brings overhead for key management. Also, autoincrement ids will not stay the same on a replace.
How can ON DUPLICATE KEY UPDATE
be emulated when using LOAD DATA INFILE?