By Alvin Alexander. Last updated: May 7, 2018
If you ever need to batch-insert a lot of records into a MySQL/MariaDB database using the JDBC PreparedStatement
(as in preparedStatement.executeBatch()
) be sure to change the MySQL URL to use the rewriteBatchedStatements
, as shown here:
"jdbc:mysql://localhost:8889/DATABASE?rewriteBatchedStatements=true"
For a recent project I needed to batch-insert about eleven million records into a MySQL database, and the runtime was about 55 minutes. Once I added rewriteBatchedStatements=true
to the MySQL URL, the batch-insert time was reduced down to only three minutes. That one little change made all the difference.