MySQL类型文本的最大长度 [英] Maximum length for MySQL type text
问题描述
我正在创建一个用于发送私人消息的表单,并希望设置一个textarea的 maxlength
值,该值适合文本的最大长度
字段在我的MySQL数据库表。
如果很多,我可以在数据库文本类型字段中指定长度,就像使用varchar一样吗?
查看最大数字:
http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
TINYBLOB,TINYTEXT L + 1字节,其中L < 2 ^ 8(255字节)
BLOB,TEXT L + 2字节,其中L < 2 ^ 16(64Kibibytes)
MEDIUMBLOB,MEDIUMTEXT L + 3字节,其中L < 2 ^ 24(16兆字节)
LONGBLOB,LONGTEXT L + 4字节,其中L < 2 ^ 32(4 Gibibytes)
L是文本字段中的字节数。因此,文本的字符的最大数量为2 16 -1(使用单字节字符)。
UTF-8 / MultiByte编码:使用MultiByte编码,每个字符可能消耗超过1字节的空间。对于UTF-8,每个字符的空间消耗在1到4个字节之间。I'm creating a form for sending private messages and want to set the maxlength
value of a textarea appropriate to the max length of a text
field in my MySQL database table. How many characters can a type text field store?
If a lot, would I be able to specify length in the database text type field as I would with varchar?
See for maximum numbers: http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
TINYBLOB, TINYTEXT L + 1 bytes, where L < 2^8 (255 Bytes)
BLOB, TEXT L + 2 bytes, where L < 2^16 (64 Kibibytes)
MEDIUMBLOB, MEDIUMTEXT L + 3 bytes, where L < 2^24 (16 Mebibytes)
LONGBLOB, LONGTEXT L + 4 bytes, where L < 2^32 (4 Gibibytes)
L is the number of bytes in your text field. So the maximmum number of chars for text is 216-1 (using single-byte characters). Means 65 535 chars(using single-byte characters).
UTF-8/MultiByte encoding: using MultiByte encoding each character might consume more than 1 byte of space. For UTF-8 space consumption is between 1 to 4 bytes per char.
这篇关于MySQL类型文本的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!