Forum Moderators: coopster
I'm importing CSV files into a table in a mySQL database using PHP, with the number of rows being anything in the region of a seven hundred thousand.
Another PHP script reads through each row in the newly created table and applys some manipulation to the data and adds it to a "master table".
Now, this is all running locally on an XP installation of Apache 2 and these scripts are taking 20 plus minutes to run in some cases.
Do I have any other alteratives to using PHP to manipulate the data on mySQL? Is there some setting I be looking at for when large volumes of data are manipulated in mySQL/PHP?
I've had to repeatedly increase the timeout figure (in php.ini) to way beyond it's default amount - this would never run on a commerical host, they'd cut my fingers off for using up so much CPU time!
Another PHP script reads through each row in the newly created table and applys some manipulation to the data and adds it to a "master table".
For example, if all you're doing is adding 2 fields, the following would be lots faster than using PHP to loop through each row, perform the calculation, then insert 1 row to the DB:
INSERT MasterTable
SELECT Field1, Field2+Field3
FROM NewTable
Again, it all depends on the actual manipulation being performed.
But as henry0 mentioned, create/keep indexes for those table that you query...
There are other ways to optimize your process, including locking your table, doing the inserts in bulk, etc, have a look at Optimaztion: Speed of insert Statements [dev.mysql.com].