Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - how many rows can I insert in one single INSERT statement?

Does it depend on the number of values sets? Does it depend on the number of bytes in the INSERT statement?

like image 340
Luistar15 Avatar asked Aug 21 '10 03:08

Luistar15


People also ask

How many rows can you insert at once MySQL?

The MySQL maximum row size limit of 65,535 bytes is demonstrated in the following InnoDB and MyISAM examples. The limit is enforced regardless of storage engine, even though the storage engine may be capable of supporting larger rows.

Can we insert multiple rows single insert statement?

Answer. Yes, instead of inserting each row in a separate INSERT statement, you can actually insert multiple rows in a single statement. To do this, you can list the values for each row separated by commas, following the VALUES clause of the statement.

How many records can one insert statement add to a table?

The Maximum number of rows you can insert in one statement is 1000 when using INSERT INTO ... VALUES... i.e. INSERT INTO TableName( Colum1) VALUES (1), (2), (3),...... upto 1000 rows.

How can insert 1000 records at a time in MySQL?

To improve insert performance you should use batch inserts. insert into table my_table(col1, col2) VALUES (val1_1, val2_1), (val1_2, val2_2); Storing records to a file and using load data infile yields even better results (best in my case), but it requires more effort.


1 Answers

You can insert infinitely large number of records using INSERT ... SELECT pattern, provided you have those records, or part of, in other tables.

But if you are hard-coding the values using INSERT ... VALUES pattern, then there is a limit on how large/long your statement is: max_allowed_packet which limits the length of SQL statements sent by the client to the database server, and it affects any types of queries and not only for INSERT statement.

like image 134
Lukman Avatar answered Sep 21 '22 10:09

Lukman