mysql Packet for query is too large (5058927 > 4194304). You can change this value on the server by

本文介绍了当遇到MySQL中Packet Too Large错误时的解决方法,包括调整客户端和服务器的max_allowed_packet参数设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mysql 插入文档内容过大

Packet for query is too large (5058927 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable.


 

   
The world's most popular open source database
   
Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 37.5Mb
PDF (A4) - 37.5Mb
PDF (RPM) - 37.0Mb
EPUB - 10.5Mb
HTML Download (TGZ) - 10.3Mb
HTML Download (Zip) - 10.3Mb
HTML Download (RPM) - 9.0Mb
Eclipse Doc Plugin (TGZ) - 11.2Mb
Eclipse Doc Plugin (Zip) - 13.4Mb
Man Pages (TGZ) - 203.9Kb
Man Pages (Zip) - 309.1Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
Excerpts from this Manual
 
MySQL 5.7 Reference Manual  /   ...  /  Packet Too Large

B.5.2.10 Packet Too Large

A communication packet is a single SQL statement sent to the MySQL server, a single row that is sent to the client, or a binary log event sent from a master replication server to a slave.

The largest possible packet that can be transmitted to or from a MySQL 5.7 server or client is 1GB.

When a MySQL client or the mysqld server receives a packet bigger than max_allowed_packet bytes, it issues an ER_NET_PACKET_TOO_LARGE error and closes the connection. With some clients, you may also get a Lost connection to MySQL server during query error if the communication packet is too large.

Both the client and the server have their own max_allowed_packet variable, so if you want to handle big packets, you must increase this variable both in the client and in the server.

If you are using the mysql client program, its default max_allowed_packet variable is 16MB. To set a larger value, start mysql like this:

shell> mysql --max_allowed_packet=32M

That sets the packet size to 32MB.

The server's default max_allowed_packet value is 4MB. You can increase this if the server needs to handle big queries (for example, if you are working with big BLOBcolumns). For example, to set the variable to 16MB, start the server like this:

shell> mysqld --max_allowed_packet=16M

You can also use an option file to set max_allowed_packet. For example, to set the size for the server to 16MB, add the following lines in an option file:

[mysqld]
max_allowed_packet=16M

It is safe to increase the value of this variable because the extra memory is allocated only when needed. For example, mysqld allocates more memory only when you issue a long query or when mysqld must return a large result row. The small default value of the variable is a precaution to catch incorrect packets between the client and server and also to ensure that you do not run out of memory by using large packets accidentally.

You can also get strange problems with large packets if you are using large BLOB values but have not given mysqld access to enough memory to handle the query. If you suspect this is the case, try adding ulimit -d 256000 to the beginning of the mysqld_safe script and restarting mysqld.

 PREV    HOME    UP    NEXT 
 User Comments
   Posted by  anand shinde on July 29, 2008
By default configuration
------------------------------------------------------------
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer = 384M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
------------------------------------------------------------

change "max_allowed_packet = 1M" to "max_allowed_packet = 32M"
   Posted by  David OBrien on August 28, 2008
On windows when importing very large databases, 
I've found it helps to NOT use extended insert statements.
The server would go away for no reason. Switching the exporter to use regular inserts solved this problem.

ie. unchecking "Create bulk INSERT statement(s)" in SQLyog or by checking No EXTENDED INSERTS in MySQL Administrator
 
   Posted by  Devin Butts on October 31, 2008
RE: mysql server has gone away error 2006
RE: Packet-too-large
RE: Windows MySQL Administrator
RE: my.ini
RE: max_allowed_packet

I had tried without success at trying to update max_allowed_packet by editing the my.ini file in Windows Vista. Seemed like nothing would work, there was no effect.

At the MySQL> command prompt, you can type:
show variables like 'max_allowed_packet'
to see if the changes you made are working.

Then I found that the values of my.ini could be changed using the MySQL Administrator. This didn't work either. It could not stop the MySQL server and every time I would click apply changes, it would say it could not apply the changes, Error 1.

Finally, I found that since I'm using Vista (bad words should be placed here), I had to run MySQL Administrator as a Windows Administrator (right click, choose Run as Administrator). Then suddenly I had the power to stop the server, make the changes I wanted and sure enough, it worked.

To change max_allowed_packet, under Startup Variables, go to the networking tab. (Took me forever to find it.)

I navigated in Windows Explorer to C:\Program Files (x86)\MySQL\MySQL Tools for 5.0\, right clicked, MySQLAdministrator.exe, choose properties and set it so it would always run as an Administrator. Now I don't have to remember.

It should be noted that MySQL install puts files in both C:\Program Files (x86)\MySQL and in C:\Program Files\MySQL

using Vista 64-bit, MySQL Administrator 1.2.12, MySQL 5.0.67
 
   Posted by  mohamed badheeu on April 23, 2009
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer = 384M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M

It helps me very much.
But I want add my esperience here.
In some servers mysql socket is in different location.
socket = /tmp/mysql.sock (if this location is different database error will come up)make sure you write your location correct.
   Posted by  Ayaz Ayaz Pasha on March 25, 2010
I copied the variables and pasted into my.ini file.

wait_timeout=28800
interactive_timeout = 28800
max_allowed_packet=64M
socket = /tmp/mysql.sock
skip-locking

Then I just restarted the MySQL service from Administrative Tools & everything worked fine(I was able to insert huge data).

Make sure you check if the parameter values are changed by typing in the command (ex.)show parameters like 'max_allowed_packet' from MySQL client(default).

Thanks

Ayaz 
 
   Posted by  Jay Scott ANDERSON on April 2, 2010
Regarding checking the existing parameter value...

show variables like 'max_allowed_packet';

...worked for me.
   Posted by  Valentin Bajrami on June 22, 2012
Instead of `show variables like 'max_allowed_packet`; you easily can use `show variables like '%max_all%'; You can issue this for other variables too.
Sign Up LoginYou must be logged in to post a comment.

Contact MySQL  |   Login  |   Register

   
The world's most popular open source database
   

Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 37.5Mb
PDF (A4) - 37.5Mb
PDF (RPM) - 37.0Mb
EPUB - 10.5Mb
HTML Download (TGZ) - 10.3Mb
HTML Download (Zip) - 10.3Mb
HTML Download (RPM) - 9.0Mb
Eclipse Doc Plugin (TGZ) - 11.2Mb
Eclipse Doc Plugin (Zip) - 13.4Mb
Man Pages (TGZ) - 203.9Kb
Man Pages (Zip) - 309.1Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
Excerpts from this Manual
 
MySQL 5.7 Reference Manual  /   ...  /  Packet Too Large

B.5.2.10 Packet Too Large

A communication packet is a single SQL statement sent to the MySQL server, a single row that is sent to the client, or a binary log event sent from a master replication server to a slave.

The largest possible packet that can be transmitted to or from a MySQL 5.7 server or client is 1GB.

When a MySQL client or the mysqld server receives a packet bigger than max_allowed_packet bytes, it issues an ER_NET_PACKET_TOO_LARGE error and closes the connection. With some clients, you may also get a Lost connection to MySQL server during query error if the communication packet is too large.

Both the client and the server have their own max_allowed_packet variable, so if you want to handle big packets, you must increase this variable both in the client and in the server.

If you are using the mysql client program, its default max_allowed_packet variable is 16MB. To set a larger value, start mysql like this:

shell> mysql --max_allowed_packet=32M
mysql --max_allowed_packet=32M

That sets the packet size to 32MB.

The server's default max_allowed_packet value is 4MB. You can increase this if the server needs to handle big queries (for example, if you are working with big BLOBcolumns). For example, to set the variable to 16MB, start the server like this:

shell> mysqld --max_allowed_packet=16M
mysqld --max_allowed_packet=16M

You can also use an option file to set max_allowed_packet. For example, to set the size for the server to 16MB, add the following lines in an option file:

[mysqld]
max_allowed_packet=16M

It is safe to increase the value of this variable because the extra memory is allocated only when needed. For example, mysqld allocates more memory only when you issue a long query or when mysqld must return a large result row. The small default value of the variable is a precaution to catch incorrect packets between the client and server and also to ensure that you do not run out of memory by using large packets accidentally.

You can also get strange problems with large packets if you are using large BLOB values but have not given mysqld access to enough memory to handle the query. If you suspect this is the case, try adding ulimit -d 256000 to the beginning of the mysqld_safe script and restarting mysqld.

 PREV    HOME    UP    NEXT 
 User Comments
   Posted by  anand shinde on July 29, 2008
By default configuration
------------------------------------------------------------
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer = 384M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
------------------------------------------------------------

change "max_allowed_packet = 1M" to "max_allowed_packet = 32M"
   Posted by  David OBrien on August 28, 2008
On windows when importing very large databases, 
I've found it helps to NOT use extended insert statements.
The server would go away for no reason. Switching the exporter to use regular inserts solved this problem.

ie. unchecking "Create bulk INSERT statement(s)" in SQLyog or by checking No EXTENDED INSERTS in MySQL Administrator
 
   Posted by  Devin Butts on October 31, 2008
RE: mysql server has gone away error 2006
RE: Packet-too-large
RE: Windows MySQL Administrator
RE: my.ini
RE: max_allowed_packet

I had tried without success at trying to update max_allowed_packet by editing the my.ini file in Windows Vista. Seemed like nothing would work, there was no effect.

At the MySQL> command prompt, you can type:
show variables like 'max_allowed_packet'
to see if the changes you made are working.

Then I found that the values of my.ini could be changed using the MySQL Administrator. This didn't work either. It could not stop the MySQL server and every time I would click apply changes, it would say it could not apply the changes, Error 1.

Finally, I found that since I'm using Vista (bad words should be placed here), I had to run MySQL Administrator as a Windows Administrator (right click, choose Run as Administrator). Then suddenly I had the power to stop the server, make the changes I wanted and sure enough, it worked.

To change max_allowed_packet, under Startup Variables, go to the networking tab. (Took me forever to find it.)

I navigated in Windows Explorer to C:\Program Files (x86)\MySQL\MySQL Tools for 5.0\, right clicked, MySQLAdministrator.exe, choose properties and set it so it would always run as an Administrator. Now I don't have to remember.

It should be noted that MySQL install puts files in both C:\Program Files (x86)\MySQL and in C:\Program Files\MySQL

using Vista 64-bit, MySQL Administrator 1.2.12, MySQL 5.0.67
 
   Posted by  mohamed badheeu on April 23, 2009
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer = 384M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M

It helps me very much.
But I want add my esperience here.
In some servers mysql socket is in different location.
socket = /tmp/mysql.sock (if this location is different database error will come up)make sure you write your location correct.
   Posted by  Ayaz Ayaz Pasha on March 25, 2010
I copied the variables and pasted into my.ini file.

wait_timeout=28800
interactive_timeout = 28800
max_allowed_packet=64M
socket = /tmp/mysql.sock
skip-locking

Then I just restarted the MySQL service from Administrative Tools & everything worked fine(I was able to insert huge data).

Make sure you check if the parameter values are changed by typing in the command (ex.)show parameters like 'max_allowed_packet' from MySQL client(default).

Thanks

Ayaz 
 
   Posted by  Jay Scott ANDERSON on April 2, 2010
Regarding checking the existing parameter value...

show variables like 'max_allowed_packet';

...worked for me.
   Posted by  Valentin Bajrami on June 22, 2012
Instead of `show variables like 'max_allowed_packet`; you easily can use `show variables like '%max_all%'; You can issue this for other variables too.
Sign Up LoginYou must be logged in to post a comment.
   © 2017, Oracle Corporation and/or its affiliates
   
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值