MySQL provides four TEXT types: TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT

In addition to CHAR and VARCHAR character types, MySQL provides us with TEXT with more functions, and its types CHAR and VARCHAR cannot be overwritten.
TEXT is useful for storing text strings that can take from 1 byte to 4 GB long format. We often find the data type used to store the article body in TEXT news sites, and the data type of product descriptions in e-commerce sites.
Unlike CHAR and VARCHAR, there is no need to specify the storage length when using TEXT as a column type. In addition, when retrieving or inserting text data (such as CHAR and), MySQL will not delete or fill spaces VARCHAR.
Please note that TEXT data is not stored in the memory of the database server, so whenever querying TEXT data, MySQL must read data from disk, which is much slower than CHAR and VARCHAR.
MySQL provides four TEXT types: TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT.
The following shows the size of each TEXT type, and assume that the character set we use requires one byte to store a character
 TINYTEXT-255 bytes (255 characters) at
most TINYTEXT can store 255 characters (2 ^ 8 = 256, 1 byte overhead).
You should use TINYTEXT columns that are less than 255 characters, have inconsistent lengths, and do not require sorting (such as blog post excerpts and article abstracts).
See the following example:
CREATE TABLE articles (
    id INT AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(255),
    summary TINYTEXT
);
In this example, we have created a new table named articles with a summary column TINYTEXT of data type.
 TEXT-64KB (65,535 characters)
This TEXT data type can hold up to 64 KB, which is equivalent to 65535 (2^16-1) characters. TEXT also requires 2 bytes of overhead.
The body of items that can be accommodated in TEXT. Consider the following example:
ALTER TABLE articles 
ADD COLUMN body TEXT NOT NULL
AFTER summary;
In this example, we use a statement to add the body column of the data type TEXT to the ALTER TABLE in the articles table.
 MEDIUMTEXT-16MB (16,777,215 characters)
MEDIUMTEXT can hold text data equivalent to 16,777,215 16MB characters. It requires 3 bytes of overhead.
The MEDIUMTEXT is used to store things like a book, white paper, etc. For example, text data with fairly large text is useful:
CREATE TABLE whitepapers (
    id INT AUTO_INCREMENT PRIMARY KEY,
    body MEDIUMTEXT NOT NULL,
    published_on DATE NOT NULL
); 
 LONGTEXT – 4GB (4,294,967,295 characters)
The LONGTEXT can store text data up to 4 GB, which is a lot of. It requires 4 bytes of overhead.

Guess you like

Origin blog.csdn.net/allway2/article/details/109642570