MySQL 数据对于 LONGBLOB 上出现的列来说太长
我有以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使它们“可以”,数据库也不是用来存储二进制文件的。在表中包含服务器上文件的路径会更有效。
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.
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