本文翻译自:Maximum length for MySQL type text
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. 我正在创建一个发送私人消息的表单,并希望设置一个textarea的maxlength
值,该值适合我的MySQL数据库表中文text
字段的最大长度。 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? 如果很多,我能否像在varchar中那样在数据库文本类型字段中指定长度?
#1楼
参考:https://stackoom.com/question/SOLd/MySQL类型文本的最大长度
#2楼
TINYTEXT: 256 bytes TINYTEXT:256字节
TEXT: 65,535 bytes 文字:65,535字节
MEDIUMTEXT: 16,777,215 bytes MEDIUMTEXT:16,777,215字节
LONGTEXT: 4,294,967,295 bytes LONGTEXT:4,294,967,295字节
#3楼
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. 如果您需要更多字符使用数据类型MEDIUMTEXT或LONGTEXT。 With VARCHAR, specifieng length is not for Storage requirement, it is only for how the data is retrieved from data base. 对于VARCHAR,指定的长度不适用于存储要求,它仅适用于从数据库中检索数据的方式。
#4楼
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 (like Arabic letters where each character takes 2 bytes), the column "Exact Max. Length Allowed" will have different length. 注意:如果使用多字节字符(如阿拉伯字母,每个字符占2个字节),“允许的最大长度”列将具有不同的长度。 For example: if you use 2-bytes characters, the exact maximum length for TINYTEXT
would be 127 characters. 例如:如果使用2字节字符,则TINYTEXT
的确切最大长度为127个字符。 Basically, it's the number of bytes allowed -1. 基本上,它是允许-1的字节数。
#5楼
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
是一种字符串数据类型,最多可以存储65,535
字符。 TEXT
is commonly used for brief articles. TEXT
通常用于简短的文章。
LONGTEXT
is a string data type with a maximum length of 4,294,967,295
characters. LONGTEXT
是一种字符串数据类型,最大长度为4,294,967,295
字符。 Use LONGTEXT
if you need to store large text, such as a chapter of a novel. 如果您需要存储大型文本(例如小说的章节),请使用LONGTEXT
。
#6楼
TEXT
is a string data type that can store up to 65,535 characters. TEXT
是一种字符串数据类型,最多可以存储65,535个字符。 But still if you want to store more data then change its data type to LONGTEXT
但是,如果您想存储更多数据, LONGTEXT
其数据类型更改为LONGTEXT
ALTER TABLE name_tabel
CHANGE text_field
LONGTEXT CHARACTER SET utf8
COLLATE utf8_general_ci
NOT NULL; ALTER TABLE name_tabel
CHANGE text_field
LONGTEXT CHARACTER SET utf8
COLLATE utf8_general_ci
NOT NULL;