MySQL: Insert 25,000,000 codes into table

83 Views Asked by At

I've got 25,000,000 codes (each code has 8 random literals) to insert into my database. We're running with MySQL and Apache Torque as ORM.

My table simplified looks like this:

table_code
id BIGINT, Primary Key (no auto-increment, bc of ORM)
code VARCHAR

What is the most efficient way to insert them? I tried this with generating Torque-Objects over night, but since the ID needs to be autoincremental, it takes forever.

Any ideas are much appreciated :) Thank you!

1

There are 1 best solutions below

5
On

Hello I think the best is to use LOAD DATA INFILE:

A link explain it's faster here : https://medium.com/@benmorel/high-speed-inserts-with-mysql-9d3dcd76f723

For your table juste do something like this :

LOAD DATA INFILE '/path/to/mycodes.csv' INTO TABLE table_code;

For more information about this function : https://dev.mysql.com/doc/refman/8.0/en/load-data.html