Yesterday I had to import some 80,000 records into 4 different tables. The data was "|" delimited and formatted almost properly. My first instinct was to use queries to insert all records in the database. I cleaned up the data and created the appropriate mappings into the database fields.
INSERT statements took some 5-10 minutes for all the records. I used PHP for the task and the restrictions on PHP scripts to execute within a certain amount of time was very annoying at first. Using the Command Line Interface I was able to get all the data in.
I figured, there has to be a better way to do things. So I researched data loading in MYSQL: http://dev.mysql.com/doc/refman/5.0/en/load-data.html
Here's how you import the data:
LOAD DATA INFILE '/tmp/data.txt' INTO TABLE test FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';
Huhuh!!! The execution time was much much faster 1-3 seconds at the most. Lesson learned!
MeasureIt