Are you perhaps using a separate query for each row? Don't forget you can add multiple rows with a single query. So for example, instead of
INSERT INTO `foo` VALUES (1, 2, 3);
INSERT INTO `foo` VALUES (4, 5, 6);
INSERT INTO `foo` VALUES (7, 8, 9);
you can issue a single query like this:
INSERT INTO `foo` VALUES (1, 2, 3), (4, 5, 6), (7, 8, 9);
Here are a couple of other optimizations that you could try:
Disable indexes
As you update a MySQL table, it will attempt to reconstruct the table's indexes after each insertion. For large insertions, it's more efficient to disable indexing temporarily while you're updating the table. To do this, send this query before you start the update:
ALTER TABLE `foo` DISABLE KEYS;
and then re-enable indexing when you're done:
ALTER TABLE `foo` ENABLE KEYS;
Disable foreign key checks
Again, these can slow things up when working with large tables. Issue the command
SET FOREIGN_KEY_CHECKS=0;
to disable foreign key checks before you start modifying the table, and
SET FOREIGN_KEY_CHECKS=1;
to re-enable these checks when you're done.