免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5621 | 回复: 2
打印 上一主题 下一主题

blob 字段Data too long for column 'details [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-17 17:29 |只看该作者 |倒序浏览
本帖最后由 liyihongcug 于 2010-08-17 17:33 编辑

但无论什么2进制字段 ,存入文件大小总是有限制
ySQL有四种BLOB类型:

  ·tinyblob:仅255个字符

  ·blob:最大限制到65K字节

  ·mediumblob:限制到16M字节

  ·longblob:可达4GB

  在每个MySQL的文档(从MySQL4.0开始)的介绍中,一个longblob列的最大允许长度依赖于在客户/服务器协议中可配置的最大包的大小和可用内存数。

  你可能对在BLOB中存储大型文件非常谨慎,但是请放心使用,MYSQL提供了这样的灵活性!最大包的大小可容易地中的在配置文件中设置。例如:

一,Windows通过文件my.ini (在系统盘)
[mysqld]
set-variable = max_allowed_packet=10M

二,linux通过etc/my.cnf
[mysqld]
max_allowed_packet = 16M

  你能指定几乎任何你需要的大小。默认是1M。
: 可以知道  尽管 ·longblob:可达4GB,但是max_allowed_packet 这个是实际限制了你的文件大小
你看看你本地my.ini或者my.cnf的  max_allowed_packet 的大小
所以每个存入字段的大小必须小于max_allowed_packet

论坛徽章:
0
2 [报告]
发表于 2010-08-17 18:23 |只看该作者
Ticket #4164 (closed defect: worksforme)

Opened 4 years ago

Last modified 4 years ago
Can't create a LongBlob column from migration
Reported by:         squeegy@beautifulpixel.com         Assigned to:         David
Priority:         normal         Milestone:        
Component:         ActiveRecord         Version:         1.0.0
Severity:         normal         Keywords:        
Cc:                        
Description ¶

At least under MySQL migration can't create a LongBlob or MediumBlob column. The following code simply create a binary column that is too small for a lot of uses.

create_table :files do |t|
  t.column :data, :binary, :null => false
end

I'm not sure about the best way to handle it though. Maybe the MySQL adapter could clue in a high limit. Or perhaps the type could be one of :binary, :binary_medium, :binary_large.
Change History
03/09/06 21:14:07 changed by david ¶

    * status changed from new to closed.
    * resolution set to worksforme.

In MySQL 4.1 and above, you can specify the length on a blob or text by using size. It'll automatically expand to the right type. Example:

create_table :files do |t|
  t.column :data, :binary, :null => false, :size => 400000
end

09/01/06 00:16:08 changed by anonymous ¶

    * severity changed from trivial to normal.
    * cc deleted.
    * component set to ActionMailer.
    * summary changed from Can to Can't create a LongBlob column from migration.
    * priority set to normal.
    * keywords deleted.
    * type changed from task to defect.

01/07/07 10:55:05 changed by bitsweat ¶

    * component changed from ActionMailer to Activ

论坛徽章:
0
3 [报告]
发表于 2011-07-19 20:27 |只看该作者
报告错误

[2011-07-19 11:51:08,446 ERROR] query.InsertSubscriptionUpdateSQLQuery - com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: Data truncation: Data too long for column 'participaIds' at row 1

Query being executed when exception was thrown:

update
java.lang.RuntimeException: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: Data

truncation: Data too long for colum

个BLOB或TEXT列,最大长度为65535(2^16-1)个字符。

MEDIUMBLOB
MEDIUMTEXT
一个BLOB或TEXT列,最大长度为16777215(2^24-1)个字符。

LONGBLOB
LONGTEXT
一个BLOB或TEXT列,最大长度为4294967295(2^32-1)个字符。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP