MySQL類型文本的最大長度

本文翻譯自: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;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章