我在我的MySQL数据库中的BLOB字段有一个问题-当上传大于大约1MB的文件时,我得到一个错误,大于max_allowed_packet是不允许的。

以下是我的尝试:

在MySQL查询浏览器中,我运行了一个像“max_allowed_packet”这样的显示变量,它给了我1048576。

然后我执行查询集全局max_allowed_packet=33554432,然后显示像'max_allowed_packet'这样的变量-它像预期的那样给我33554432。

但是当我重新启动MySQL服务器时,它神奇地回到1048576。我哪里做错了?

额外的问题,是否可以压缩一个BLOB字段?


当前回答

对于任何在Amazon RDS服务上运行MySQL的人来说,这个更改是通过参数组完成的。您需要创建一个新的PG或使用一个现有的PG(除了默认的只读PG)。

您应该搜索max_allowed_packet参数,更改其值,然后点击保存。

回到您的MySQL实例,如果您创建了一个新的PG,您应该将PG附加到您的实例(您可能需要重新启动)。 如果您更改了已附加到实例的PG,则更改将在不重新引导的情况下应用到已附加该PG的所有实例。

其他回答

max_allowed_packet变量可以通过运行查询全局设置。

但是,如果您没有在my.ini文件中更改它(如dragon112所建议的那样),则该值将在服务器重新启动时重置,即使您全局地设置了它。

更改每个人允许的最大数据包为1GB,直到服务器重新启动。

SET GLOBAL max_allowed_packet=1073741824;

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

Win+R(“运行”的快捷方式),输入服务。msc,输入 你可以找到一个像'MySQL56'这样的条目,右键单击它,选择属性 你可以看到“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时得到这个错误,我不明白,因为我在[mysqld]节下的my.cnf中设置了这个。一旦我发现我可以设置它为[mysqldump],我设置了值,我的备份完成没有问题。

按照所有的指示,这就是我所做和工作的:

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_packet已经从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_packet=1073741824之后,服务器将拥有新的max_allowed_packet,直到它重新启动,就像前面有人说的那样。

此错误是因为您的数据包含大于设定值。

只需要写下max_allowed_packed=500M 或者你可以计算500*1024k,如果你想用它来代替500M。

现在重新启动MySQL。