The fastest way to insert 4 million rows (16 MB of data) is to use the infile download data - http://dev.mysql.com/doc/refman/5.0/en/load-data.html
therefore, if possible, generate the csv file, then use the infile download data ..
hope this helps :)
EDIT
So, I took one of your source rolloff.dat data files and wrote a quick and dirty program to convert it to the following csv format.
Download frames.dat from here: http://rapidshare.com/files/454896698/frames.dat
Frames.dat
patient_name, sample_date dd/mm/yyyy, frame_time (ms), frame 0..248, row 0..255, col 0..62, value "Krulle (opnieuw) Krupp",04/03/2010,0.00,0,5,39,0.4 "Krulle (opnieuw) Krupp",04/03/2010,0.00,0,5,40,0.4 ... "Krulle (opnieuw) Krupp",04/03/2010,0.00,0,10,42,0.4 "Krulle (opnieuw) Krupp",04/03/2010,0.00,0,10,43,0.4 "Krulle (opnieuw) Krupp",04/03/2010,7.94,1,4,40,0.4 "Krulle (opnieuw) Krupp",04/03/2010,7.94,1,5,39,0.4 "Krulle (opnieuw) Krupp",04/03/2010,7.94,1,5,40,0.7 "Krulle (opnieuw) Krupp",04/03/2010,7.94,1,6,44,0.7 "Krulle (opnieuw) Krupp",04/03/2010,7.94,1,6,45,0.4 ... "Krulle (opnieuw) Krupp",04/03/2010,1968.25,248,241,10,0.4 "Krulle (opnieuw) Krupp",04/03/2010,1968.25,248,241,11,0.4 "Krulle (opnieuw) Krupp",04/03/2010,1968.25,248,241,12,1.1 "Krulle (opnieuw) Krupp",04/03/2010,1968.25,248,241,13,1.4 "Krulle (opnieuw) Krupp",04/03/2010,1968.25,248,241,14,0.4
The file contains data only for frames that have values โโfor each line and col, therefore zeros are excluded. 24,799 data lines were created from your source file.
Then I created a temporary (intermediate) loading table into which the frames.dat file is loaded. This is a temporary table that will allow you to manipulate / transform the data before loading into the corresponding production / reporting tables.
drop table if exists sample_temp; create table sample_temp ( patient_name varchar(255) not null, sample_date date, frame_time decimal(6,2) not null default 0, frame_id tinyint unsigned not null, row_id tinyint unsigned not null, col_id tinyint unsigned not null, value decimal(4,1) not null default 0, primary key (frame_id, row_id, col_id) ) engine=innodb;
It remains only to load the data (note: I use windows, so you will need to edit this script to make it compatible with linux - check the path names and change '\ r \ n' to '\ n')
truncate table sample_temp; start transaction; load data infile 'c:\\import\\frames.dat' into table sample_temp fields terminated by ',' optionally enclosed by '"' lines terminated by '\r\n' ignore 1 lines ( patient_name, @sample_date, frame_time, frame_id, row_id, col_id, value ) set sample_date = str_to_date(@sample_date,'%d/%m/%Y'); commit; Query OK, 24799 rows affected (1.87 sec) Records: 24799 Deleted: 0 Skipped: 0 Warnings: 0
24K rows were downloaded in 1.87 seconds.
Hope this helps :)