gpt4 book ai didi

mysql - 在 MySQL 中,blob 数据的长度与其数据包大小(以字节为单位)有何关联?

转载 作者:行者123 更新时间:2023-11-29 10:42:27 24 4
gpt4 key购买 nike

我正在尝试处理一个数据库,该数据库具有无法使用 MySQL (5.6.36) 读取的长BLOB 表。

当 max_allowed_pa​​cket 为 1024MiB 时,我无法选择长度为 26840023 (~25MiB) 的列的内容。

mysql> select bid, length(batch) from batch where bid = 32;
+-----+---------------+
| bid | length(batch) |
+-----+---------------+
| 32 | 26840023 |
+-----+---------------+
1 row in set (0.00 sec)

mysql> SHOW VARIABLES WHERE variable_name = 'max_allowed_packet';
+--------------------+------------+
| Variable_name | Value |
+--------------------+------------+
| max_allowed_packet | 1073741824 |
+--------------------+------------+
1 row in set (0.00 sec)

mysql> select batch from batch where bid = 32 limit 1;
ERROR 2020 (HY000): Got packet bigger than 'max_allowed_packet' bytes

虽然这不是我的数据库,而且我个人认为我不会将此类数据存储在 MySQL 中,但我正在尝试了解 max_allowed_pa​​cket 限制与实际检索该信息之间的关系。

对我来说,长度约为 25MiB 的列需要近 40 倍的字节来表达其内容,这似乎很奇怪。我是否误解了这里发生的事情?对于任何给定长度的 blob 数据是否有合适的 max_allowed_pa​​cket,或者那里没有可靠的相关性?

我一直认为长度不是确切的字节数(某些字符可能需要更多字节来表示),但(至少)每个字符长度 40 个字节对我来说是无法解释的。是否有某种方法可以确定给定 blob 值的适当 max_allowed_pa​​cket 是什么?

最佳答案

该数据包确实有(大约)25MB。这里的问题(很可能)是服务器和客户端都有自己的 max_allowed_pa​​cket 设置。 show Variables 将仅显示服务器设置。根据documentation

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. [...] 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.

有效允许的数据包大小(遗憾的是您无法查询)将由服务器或客户端的较低值决定,因此请在配置文件中设置该值(在[mysql]下)或命令行。

对于其他客户端,您可能不需要调整它,因为

The default max_allowed_packet value built in to the client library is 1GB.

关于mysql - 在 MySQL 中,blob 数据的长度与其数据包大小(以字节为单位)有何关联?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45225227/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com