Since there are a few arguments, I thought I would try a benchmark, but first
CREATE TABLE `tbl_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
`number` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB
I then generate, SQL queries of the form in the question with 2 lines of python.
Scenario 1:
Many single inserts with the queries each being exactly the same
INSERT INTO tbl_user VALUES(NULL,'A','9999999');
INSERT INTO tbl_user VALUES(NULL,'A','9999999');
1000 Rows; Average (mean) running time of three executions 45.80 seconds
5000 Rows; single run 220 seconds
Scenario 2:
A single query to insert a 1000 rows, it looks like this:
INSERT INTO tbl_user VALUES(NULL,'A','9999999'),
(NULL,'A','9999999'),
(NULL,'A','9999999'),
(NULL,'A','9999999'),
1000 rows Average (mean) running time of three executions 0.17 Seconds
5000 rows Average (mean) running time of three executions 0.48
10000 rows Average (mean) running time of three executions 1.06
Scenario 3:
Similar to scenario 1 but with a START TRANSACTION and COMMIT wrapped around the insert statements
1000 rows Average (mean) running time of three executions 0.16 seconds
5000 rows Average (mean) running time of three executions 0.48
10000 rows Average (mean) running time of three executions 0.91
Conclusion:
Scenario 2, which is what's proposed in two other answers indeed outperforms scenario 1 in a big way. With this data, it's hard to choose between 2 and 3 though. More rigorous testing with a larger number of inserts is required. But without that information i would probably go with three, the reason being that parsing a very large string usually has it's overheads and so does preparing one! I suspect that if we tried to insert about 50,000 records at once in a single statement it might actually be a lot slower.
max_packet_size. Option number 2 is also a bit more resource intensive to parse. You always want to avoid that, it's also harder to debug if anything bad happens. Therefore - option #3 is the fastest. AddBEGIN TRANSACTIONad the beginning andCOMMITat the end. Good luck.