Re: Why is my MySQL database so slow Hi,
two things come to my mind spontanously that should improve performence,
which are a) use a transaction for the INSERT statements - that prevents
MySQL from flushing the index for every row (instead, MySQL only does it
once when you commit the transaction) and b) prepare the statement, because
it only requires to transfer the actual data for every row and not the whole
SQL command.
One further thing that should improve the performence slightly would be to
put the $table = "mytable"; line outside the for loop (as it doesn't change
within the loop, it works as well to declare it outside, so this line of
code runs only once instead of 2,000 times). Finally, if you use MySQL 5,
the best solution would be to insert the rows in a Stored Procedure (this
would require only one single roundtrip to the database server, which should
give performance a boost).
However, 600 rows in 30 seconds still looks very slow - maybe there are
other factors involved which are outside the scope of programming and
database design.
Markus |