MySQL - how many rows can I insert in one single I

2020-01-26 05:23发布

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

8条回答
Evening l夕情丶
2楼-- · 2020-01-26 05:48

Ideally, Mysql allow infinite number of rows creation in single insert (at once) but when a

MySQL client or the mysqld server receives a packet bigger than max_allowed_packet bytes, it issues a Packet too large error and closes the connection.

To view what the default value is for max_allowed_packet variable, execute the following command in in MySQL:

show variables like 'max_allowed_packet';

Standard MySQL installation has a default value of 1048576 bytes (1MB). This can be increased by setting it to a higher value for a session or connection.

This sets the value to 500MB for everyone (that's what GLOBAL means):

SET GLOBAL max_allowed_packet=524288000;

check your change in new terminal with new connection:

show variables like 'max_allowed_packet';

Now it should work without any error for infinite records insert. Thanks

查看更多
Juvenile、少年°
3楼-- · 2020-01-26 05:59

It is limited by max_allowed_packet.
You can specify by using: mysqld --max_allowed_packet=32M It is by default 16M.
You can also specify in my.cnf in /etc/mysql/

查看更多
Explosion°爆炸
4楼-- · 2020-01-26 06:01

Query is limited by max_allowed_packet in general.

查看更多
Viruses.
5楼-- · 2020-01-26 06:02

refer to http://forums.mysql.com/read.php?20,161869, it's related with your mysql's configuration: max_allowed_packet, bulk_insert_buffer_size, key_buffer_size.

查看更多
一夜七次
6楼-- · 2020-01-26 06:03

I believe there's no defined number of rows you're limited to inserting per INSERT, but there may be some sort of maximum size for queries in general.

查看更多
The star\"
7楼-- · 2020-01-26 06:05

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.

查看更多
登录 后发表回答