如何更改 max_allowed_pa​​cket 大小

2021-11-20 00:00:00 mysql

我的 MySQL 数据库中的 BLOB 字段有问题 - 当上传大于约 1MB 的文件时,我收到一个错误 不允许大于 max_allowed_pa​​cket 的数据包.

I am having a problem with BLOB fields in my MySQL database - when uploading files larger than approx 1MB I get an error Packets larger than max_allowed_packet are not allowed.

这是我尝试过的:

在 MySQL 查询浏览器中,我运行了一个 show variables like 'max_allowed_pa​​cket' 这给了我 1048576.

In MySQL Query Browser I ran a show variables like 'max_allowed_packet' which gave me 1048576.

然后我执行查询 set global max_allowed_pa​​cket=33554432 后跟 show variables like 'max_allowed_pa​​cket' - 它按预期给了我 33554432.

Then I execute the query set global max_allowed_packet=33554432 followed by show variables like 'max_allowed_packet' - it gives me 33554432 as expected.

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

But when I restart the MySQL server it magically goes back to 1048576. What am I doing wrong here?

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

Bonus question, is it possible to compress a BLOB field?

推荐答案

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

Change in the my.ini or ~/.my.cnf file by including the single line under [mysqld] or [client] section in your file:

max_allowed_packet=500M

然后重启 MySQL 服务就大功告成了.

then restart the MySQL service and you are done.

有关详细信息,请参阅文档.

See the documentation for further information.

相关文章