Php – Large MySQL Batch Inserts From PHP: Run insert from script, or save as SQL file

file handlingMySQLPHPsql

We have a large dataset that's current residing in many, many spreadsheets.
I've been tasked with getting part of that data into our MySQL DB.
When all is said and done, I will probably be inserting somewhere around 3 million rows.

I intend to collect the inserts into batches of about a quarter-million or so (parsing through it with PHP).
Initially, my plan was to just run/send those batch INSERTs straight from my script.
More recently, though, I thought about actually writing out the INSERTs to .sql files for later importing.

I tried to google around on this a little … didn't find much.
Are there any real pro's/con's one way or the other?
If not, I'm inclined to stick with my original plan.
Otherwise, I'm completely open to suggestions.

Best Answer

The only major plus I see one way or the other is that by making the .sql files, if some problem occurs and you have to blow away the database and re-do the import process, you don't have to re-run your scripts against the spreadsheets. Or looking at it another way, you can test the process on a test server before doing the actual import.

But if this is just a one time thing, ultimately, either would suffice.

Related Topic