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?
我创建了一个用于发送私有消息的表单,并希望将textarea的maxlength值设置为MySQL数据库表中文本字段的最大长度。类型文本字段存储多少字符?
If a lot, would I be able to specify length in the database text type field as I would with varchar?
如果有很多,我是否能够在数据库文本类型字段中指定长度,就像使用varchar一样?
7 个解决方案
#1
565
See for maximum numbers: http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
查看最大的数字:http://dev.mysql.com/doc/refman/5.0/ en/storagerequirements.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).
L是文本字段中的字节数。因此,文本的最大字符数是216-1(使用单字节字符)。表示65 535字符(使用单字节字符)。
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.
UTF-8/多字节编码:每个字符使用多字节编码可能消耗超过1字节的空间。对于UTF-8空间消耗是每字符1到4字节。
#2
94
TINYTEXT: 256 bytes
TEXT: 65,535 bytes
MEDIUMTEXT: 16,777,215 bytes
LONGTEXT: 4,294,967,295 bytes
TINYTEXT: 256字节文本:65,535字节MEDIUMTEXT: 16,777,215字节长文本:4,294,967,295字节。
#3
33
Type | Approx. Length | Exact Max. Length Allowed
-----------------------------------------------------------
TINYTEXT | 256 Bytes | 255 characters
TEXT | 64 Kilobytes | 65,535 characters
MEDIUMTEXT | 16 Megabytes | 16,777,215 characters
LONGTEXT | 4 Gigabytes | 4,294,967,295 characters
Note: If using multibyte characters, the column "Exact Max. Length Allowed" will have different length. For example: if you use 2-bytes characters, the exact maximum length for TINYTEXT
would be 127 characters. Basically, it's the number of bytes allowed -1.
注意:如果使用多字节字符,列“精确最大值”。长度允许的长度是不同的。例如:如果您使用2字节字符,TINYTEXT的最大长度将是127个字符。基本上是允许的字节数-1。
#4
17
Acording to http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html, the limit is L + 2 bytes, where L < 2^16
, or 64k.
根据http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html,极限是L + 2字节,L < 2 ^ 16或64 k。
You shouldn't need to concern yourself with limiting it, it's automatically broken down into chunks that get added as the string grows, so it won't always blindly use 64k.
您不必担心限制它,它会自动分解成块,随着字符串的增长而增加,所以它不会总是盲目地使用64k。
#5
7
How many characters can a type text field store?
类型文本字段存储多少字符?
According to Documentation You can use maximum of 21,844 characters if the charset is UTF8
根据文档,如果字符集是UTF8,您可以使用最多21,844个字符。
If a lot, would I be able to specify length in the db text type field as I would with varchar?
如果有很多,我是否能够像varchar那样在db文本类型字段中指定长度?
You dont need to specify the length. If you need more character use data types MEDIUMTEXT or LONGTEXT. With VARCHAR, specifieng length is not for Storage requirement, it is only for how the data is retrieved from data base.
您不需要指定长度。如果您需要更多的字符使用数据类型的中文字或长文本。对于VARCHAR, specifieng长度不是用于存储需求的,它只是用于从数据库中检索数据的方式。
#6
3
TINYTEXT 256 bytes TEXT 65,535 bytes ~64kb MEDIUMTEXT 16,777,215 bytes ~16MB LONGTEXT 4,294,967,295 bytes ~4GB
TINYTEXT
is a string data type that can store up to to 255
characters.
TINYTEXT是一种字符串数据类型,可以存储到255个字符。
TEXT
is a string data type that can store up to 65,535
characters. TEXT
is commonly used for brief articles.
文本是一种字符串数据类型,可以存储多达65,535个字符。文本通常用于简要的文章。
LONGTEXT
is a string data type with a maximum length of 4,294,967,295
characters. Use LONGTEXT
if you need to store large text, such as a chapter of a novel.
LONGTEXT是一个字符串数据类型,最大长度为4,294,967,295个字符。如果需要存储大型文本,比如小说的一章,可以使用LONGTEXT。
#7
0
TEXT
is a string data type that can store up to 65,535 characters. But still if you want to store more data then change its data type to LONGTEXT
文本是一种字符串数据类型,可以存储多达65,535个字符。但是,如果您想存储更多的数据,那么将其数据类型更改为LONGTEXT。
ALTER TABLE name_tabel
CHANGE text_field
LONGTEXT CHARACTER SET utf8
COLLATE utf8_general_ci
NOT NULL;
更改表name_tabel更改text_field LONGTEXT字符集utf8 COLLATE utf8_general_ci不为空;
#1
565
See for maximum numbers: http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
查看最大的数字:http://dev.mysql.com/doc/refman/5.0/ en/storagerequirements.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).
L是文本字段中的字节数。因此,文本的最大字符数是216-1(使用单字节字符)。表示65 535字符(使用单字节字符)。
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.
UTF-8/多字节编码:每个字符使用多字节编码可能消耗超过1字节的空间。对于UTF-8空间消耗是每字符1到4字节。
#2
94
TINYTEXT: 256 bytes
TEXT: 65,535 bytes
MEDIUMTEXT: 16,777,215 bytes
LONGTEXT: 4,294,967,295 bytes
TINYTEXT: 256字节文本:65,535字节MEDIUMTEXT: 16,777,215字节长文本:4,294,967,295字节。
#3
33
Type | Approx. Length | Exact Max. Length Allowed
-----------------------------------------------------------
TINYTEXT | 256 Bytes | 255 characters
TEXT | 64 Kilobytes | 65,535 characters
MEDIUMTEXT | 16 Megabytes | 16,777,215 characters
LONGTEXT | 4 Gigabytes | 4,294,967,295 characters
Note: If using multibyte characters, the column "Exact Max. Length Allowed" will have different length. For example: if you use 2-bytes characters, the exact maximum length for TINYTEXT
would be 127 characters. Basically, it's the number of bytes allowed -1.
注意:如果使用多字节字符,列“精确最大值”。长度允许的长度是不同的。例如:如果您使用2字节字符,TINYTEXT的最大长度将是127个字符。基本上是允许的字节数-1。
#4
17
Acording to http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html, the limit is L + 2 bytes, where L < 2^16
, or 64k.
根据http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html,极限是L + 2字节,L < 2 ^ 16或64 k。
You shouldn't need to concern yourself with limiting it, it's automatically broken down into chunks that get added as the string grows, so it won't always blindly use 64k.
您不必担心限制它,它会自动分解成块,随着字符串的增长而增加,所以它不会总是盲目地使用64k。
#5
7
How many characters can a type text field store?
类型文本字段存储多少字符?
According to Documentation You can use maximum of 21,844 characters if the charset is UTF8
根据文档,如果字符集是UTF8,您可以使用最多21,844个字符。
If a lot, would I be able to specify length in the db text type field as I would with varchar?
如果有很多,我是否能够像varchar那样在db文本类型字段中指定长度?
You dont need to specify the length. If you need more character use data types MEDIUMTEXT or LONGTEXT. With VARCHAR, specifieng length is not for Storage requirement, it is only for how the data is retrieved from data base.
您不需要指定长度。如果您需要更多的字符使用数据类型的中文字或长文本。对于VARCHAR, specifieng长度不是用于存储需求的,它只是用于从数据库中检索数据的方式。
#6
3
TINYTEXT 256 bytes TEXT 65,535 bytes ~64kb MEDIUMTEXT 16,777,215 bytes ~16MB LONGTEXT 4,294,967,295 bytes ~4GB
TINYTEXT
is a string data type that can store up to to 255
characters.
TINYTEXT是一种字符串数据类型,可以存储到255个字符。
TEXT
is a string data type that can store up to 65,535
characters. TEXT
is commonly used for brief articles.
文本是一种字符串数据类型,可以存储多达65,535个字符。文本通常用于简要的文章。
LONGTEXT
is a string data type with a maximum length of 4,294,967,295
characters. Use LONGTEXT
if you need to store large text, such as a chapter of a novel.
LONGTEXT是一个字符串数据类型,最大长度为4,294,967,295个字符。如果需要存储大型文本,比如小说的一章,可以使用LONGTEXT。
#7
0
TEXT
is a string data type that can store up to 65,535 characters. But still if you want to store more data then change its data type to LONGTEXT
文本是一种字符串数据类型,可以存储多达65,535个字符。但是,如果您想存储更多的数据,那么将其数据类型更改为LONGTEXT。
ALTER TABLE name_tabel
CHANGE text_field
LONGTEXT CHARACTER SET utf8
COLLATE utf8_general_ci
NOT NULL;
更改表name_tabel更改text_field LONGTEXT字符集utf8 COLLATE utf8_general_ci不为空;