如何更改max_allowed_pa​​cket大小

我有我的MySQL数据库中的BLOB字段的问题 – 当上传大于大约1MB的文件时,我得到一个错误Packets larger than max_allowed_packet are not allowed.

这是我试过的:

在MySQL查询浏览器中,我运行了一个show variables like 'max_allowed_packet' ,它给了我1048576。

然后我执行查询set global max_allowed_packet=33554432后面show variables like 'max_allowed_packet' – 它给了我33554432按预期。

但是,当我重新启动MySQL服务器神奇地回到1048576.我在这里做错了什么?

奖金的问题,是否有可能压缩一个BLOB字段?

更改my.ini~/.my.cnf文件,在文件中包含[mysqld]部分下的单行:

 max_allowed_packet=500M 

然后重新启动MySQL服务,你就完成了。

请参阅文档以获取更多信息。

可以通过运行查询全局设置max_allowed_pa​​cketvariables。

但是,如果不在my.ini文件中更改它(如dragon112build议的那样),即使在全局设置时,该值也会在服务器重新启动时重置。

要更改每个人的设置,直到服务器重新启动:

 SET GLOBAL max_allowed_packet=1073741824; 

我的一个初级开发者遇到了一个问题,为我修改了这个问题,所以我想我会更详细地为linux用户进行扩展:

1)打开terminal

2)ssh root @ YOURIP

3)inputroot密码

4)nano /etc/mysql/my.cnf(如果命令无法识别,请先尝试vi,然后重复:yum install nano)

5)在[MYSQLD]部分下添加:max_allowed_pa​​cket = 256M(明显resize)。 他犯了一个错误,把它放在文件的底部,所以它不起作用。

在这里输入图像描述

6)控制+ O(保存),然后确认(确认),然后控制+ X(退出文件)

7)服务mysqld重启

8)你可以检查phpmyadmin的variables部分的变化

我想有些人也想知道如何在你的电脑上findmy.ini文件。 对于windows用户,我认为最好的办法如下:

  1. Win + R (“运行”的快捷方式),键入services.msc ,回车
  2. 你可以find一个像“MySQL56”的条目,右键点击它,select属性
  3. 你可以看到“D:/ Program Files / MySQL / MySQL Server 5.6 / bin \ mysqld”–defaults-file =“D:\ ProgramData \ MySQL \ MySQL Server 5.6 \ my.ini”MySQL56

我从http://bugs.mysql.com/bug.php?id=68516得到了这个答案;

如果在执行备份时出现此错误,可以在my.cnf设置max_allowed_packet ,特别是mysqldump

 [mysqldump] max_allowed_packet=512M 

我在执行一个mysqldump时候不断收到这个错误,而且我不明白,因为我在my.cnf下的[mysqld]部分有这个设置。 一旦我想出了我可以设置为[mysqldump]并设置了值,我的备份完成没有问题。

对于那些运行wamp mysql的服务器

Wamp托盘图标 – > MySql – > my.ini

 [wampmysqld] port = 3306 socket = /tmp/mysql.sock key_buffer_size = 16M max_allowed_packet = 16M // --> changing this wont solve sort_buffer_size = 512K 

向下滚动到最后直到find

 [mysqld] port=3306 explicit_defaults_for_timestamp = TRUE 

在两者之间添加一行packet_size

 [mysqld] port=3306 max_allowed_packet = 16M explicit_defaults_for_timestamp = TRUE 

检查它是否与这个查询一起工作

 Select @@global.max_allowed_packet; 

遵循所有指示,这就是我所做的工作:

 mysql> SELECT CONNECTION_ID();//This is my ID for this session. +-----------------+ | CONNECTION_ID() | +-----------------+ | 20 | +-----------------+ 1 row in set (0.00 sec) mysql> select @max_allowed_packet //Mysql do not found @max_allowed_packet +---------------------+ | @max_allowed_packet | +---------------------+ | NULL | +---------------------+ 1 row in set (0.00 sec) mysql> Select @@global.max_allowed_packet; //That is better... I have max_allowed_packet=32M inside my.ini +-----------------------------+ | @@global.max_allowed_packet | +-----------------------------+ | 33554432 | +-----------------------------+ 1 row in set (0.00 sec) mysql> **SET GLOBAL max_allowed_packet=1073741824**; //Now I'm changing the value. Query OK, 0 rows affected (0.00 sec) mysql> select @max_allowed_packet; //Mysql not found @max_allowed_packet +---------------------+ | @max_allowed_packet | +---------------------+ | NULL | +---------------------+ 1 row in set (0.00 sec) mysql> Select @@global.max_allowed_packet;//The new value. And I still have max_allowed_packet=32M inisde my.ini +-----------------------------+ | @@global.max_allowed_packet | +-----------------------------+ | 1073741824 | +-----------------------------+ 1 row in set (0.00 sec) 

所以,正如我们所看到的,max_allowed_pa​​cket已经从my.ini以外改变了。

让我们离开会话再次检查:

 mysql> exit Bye C:\Windows\System32>mysql -uroot -pPassword Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 21 Server version: 5.6.26-log MySQL Community Server (GPL) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> SELECT CONNECTION_ID();//This is my ID for this session. +-----------------+ | CONNECTION_ID() | +-----------------+ | 21 | +-----------------+ 1 row in set (0.00 sec) mysql> Select @@global.max_allowed_packet;//The new value still here and And I still have max_allowed_packet=32M inisde my.ini +-----------------------------+ | @@global.max_allowed_packet | +-----------------------------+ | 1073741824 | +-----------------------------+ 1 row in set (0.00 sec) Now I will stop the server 2016-02-03 10:28:30 - Server is stopped mysql> SELECT CONNECTION_ID(); ERROR 2013 (HY000): Lost connection to MySQL server during query Now I will start the server 2016-02-03 10:31:54 - Server is running C:\Windows\System32>mysql -uroot -pPassword Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.6.26-log MySQL Community Server (GPL) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> SELECT CONNECTION_ID(); +-----------------+ | CONNECTION_ID() | +-----------------+ | 9 | +-----------------+ 1 row in set (0.00 sec) mysql> Select @@global.max_allowed_packet;//The previous new value has gone. Now I see what I have inside my.ini again. +-----------------------------+ | @@global.max_allowed_packet | +-----------------------------+ | 33554432 | +-----------------------------+ 1 row in set (0.00 sec) 

结论,在SET GLOBAL max_allowed_pa​​cket = 1073741824之后,服务器将会有新的max_allowed_pa​​cket,直到它重启为止,正如之前所说的那样。

这个错误是因为你的数据包含了较大的设定值。

只要写下max_allowed_packed=500M或者你可以计算出500 * 1024k,如果你愿意,可以用500M而不是500M。

现在只需重新启动MySQL。

许多回答者发现了这个问题,并已经给出了解决scheme。

我只是想提出另一个解决scheme,它正在改变工具Mysql Workbench中的Glogalvariables值 。 那是因为如果你使用在服务器上本地运行的Workbench(或通过SSH连接)

您只需连接到您的实例,然后进入菜单:

服务器 – >选项文件 – >networking – > max_allowed_pa​​cked

您设置所需的值,然后您需要重新启动MySql服务

如果你想上传大尺寸的图片或数据库中的数据。 只要将数据types改为'BIG BLOB'