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

以下是我的尝试:

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

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

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

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


当前回答

设置全局max_allowed_packet=10000000000;

其他回答

对于那些运行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

向下滚动到最后,直到你找到

[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;

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

[mysqldump]
max_allowed_packet=512M

我一直在执行mysqldump时得到这个错误,我不明白,因为我在[mysqld]节下的my.cnf中设置了这个。一旦我发现我可以设置它为[mysqldump],我设置了值,我的备份完成没有问题。

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

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

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

SET GLOBAL max_allowed_packet=1073741824;

如果你想上传大尺寸的图片或数据库中的数据。只需将数据类型更改为“BIG BLOB”。

我的一个初级开发人员在为我修改这个问题时遇到了问题,所以我想我应该为linux用户扩展更详细的内容:

open terminal ssh root@YOURIP enter root password nano /etc/mysql/my.cnf (if command is not recognized do this first or try vi then repeat: yum install nano ) add the line: max_allowed_packet=256M (obviously adjust size for whatever you need) under the [MYSQLD] section. He made a mistake of putting it at the bottom of the file first so it did not work. Control + O (save) then Enter (confirm) then Control + X (exit file) service mysqld restart You can check the change in the variables section on phpmyadmin