MySQL 数据对于 LONGBLOB 上出现的列来说太长

发布于 2024-09-29 01:50:57 字数 474 浏览 0 评论 0原文

我有以下 MySQL(版本 5.1)表(InnoDB):

Username varchar(50)  
Sequence int(11)  
FileType varchar(10)  
Photo longblob -- here
PhotoSize int(11)  
Timestamp datetime

尝试插入 byte[] 96.7KB 失败并出现错误:

第 1 行“照片”列的数据太长

插入 byte[](大小 37.2KB)效果很好。我不知道临界点是什么。

我用 google 搜索了一下,很多人说解决方案是将其从 BLOB 更改为 LONGBLOB。这不起作用。其他人说将 Max_Allowed_Packet 更改为 16M(在 my.ini 文件中)可以解决问题。这也行不通。

有人可以帮助我吗?

I have the following MySQL (version 5.1) table (InnoDB):

Username varchar(50)  
Sequence int(11)  
FileType varchar(10)  
Photo longblob -- here
PhotoSize int(11)  
Timestamp datetime

Attempting to insert a byte[] 96.7KB fails with the error:

Data Too Long For Column 'Photo' At Row 1

Inserting byte[] (size 37.2KB) works fine. I don't know what the tipping point is.

I googled it and many said the solution was to change it from BLOB to LONGBLOB. This didn't work. Others said changing to Max_Allowed_Packet to 16M (in the my.ini file) would solve the problem. This also didn't work.

Can anyone help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

随遇而安 2024-10-06 01:50:57

即使它们“可以”,数据库也不是用来存储二进制文件的。在表中包含服务器上文件的路径会更有效。

Even if they "can", databases are not made to stock binary files. It's more efficient to have in your table the path of the files on your server.

纸短情长 2024-10-06 01:50:57

LONGBLOB

最大长度为 4,294,967,295 或 4GB (232 – 1) 字节的 BLOB 列。 LONGBLOB 列的有效最大长度取决于客户端/服务器协议中配置的最大数据包大小和可用内存。每个 LONGBLOB 值都使用四字节长度前缀来存储,该前缀指示该值中的字节数。

您确定编辑了正确的 my.ini 文件吗?您检查了加载的配置值吗?如果您使用 phpMyAdmin,请转到“变量”选项卡并检查“最大允许数据包”值,默认值为 16,777,216,您的应该更像是 1,000,000,000

LONGBLOB

A BLOB column with a maximum length of 4,294,967,295 or 4GB (232 – 1) bytes. The effective maximum length of LONGBLOB columns depends on the configured maximum packet size in the client/server protocol and available memory. Each LONGBLOB value is stored using a four-byte length prefix that indicates the number of bytes in the value.

Are you sure that you have edited the right my.ini file? Did you check in your loaded configuration values? If you are using phpMyAdmin go to "Variables" tab and check "max allowed packet" value, default is 16,777,216, your should be way more something like 1,000,000,000

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文