MySQL Variables max_allowed_packet 数据库 参数变量解释及正确配置使用
本站中文解释
Max_allowed_packet是MySQL服务器一次传送的最大数据包大小,主要用于限制服务器传输的最大数据量,以防止MySQL服务器崩溃、内存溢出或者备份被破坏。
要设置Max_allowed_packet参数,需在MySQL服务器的my.cnf文件中添加:
max_allowed_packet = 数据包大小
其中,数据包大小单位为字节,例如设置最大数据包大小为10M,则可设置为:max_allowed_packet=10485760(Bytes)。
修改后需重新启动MySQL服务器,以更新Max_allowed_packet参数值。
官方英文解释
max_allowed_packet
Command-Line Format | --max-allowed-packet=# |
---|---|
System Variable | max_allowed_packet |
Scope | Global, Session |
Dynamic | Yes |
Type | Integer |
Default Value | 4194304 |
Minimum Value | 1024 |
Maximum Value | 1073741824 |
Unit | bytes |
Block Size | 1024 |
The maximum size of one packet or any generated/intermediate
string, or any parameter sent by the
mysql_stmt_send_long_data()
C
API function. The default is 4MB.
The packet message buffer is initialized to
net_buffer_length
bytes, but
can grow up to
max_allowed_packet
bytes when
needed. This value by default is small, to catch large
(possibly incorrect) packets.
You must increase this value if you are using large
BLOB
columns or long strings.
It should be as big as the largest
BLOB
you want to use. The
protocol limit for
max_allowed_packet
is 1GB.
The value should be a multiple of 1024; nonmultiples are
rounded down to the nearest multiple.
When you change the message buffer size by changing the value
of the max_allowed_packet
variable, you should also change the buffer size on the client
side if your client program permits it. The default
max_allowed_packet
value
built in to the client library is 1GB, but individual client
programs might override this. For example,
mysql and mysqldump have
defaults of 16MB and 24MB, respectively. They also enable you
to change the client-side value by setting
max_allowed_packet
on the
command line or in an option file.
The session value of this variable is read only. The client
can receive up to as many bytes as the session value. However,
the server cannot send to the client more bytes than the
current global
max_allowed_packet
value.
(The global value could be less than the session value if the
global value is changed after the client connects.)