Home > Database > Mysql Tutorial > body text

What does mysql use to store text?

(*-*)浩
Release: 2019-06-04 17:47:31
Original
4464 people have browsed it

Mysql uses the following three types when storing text.

What does mysql use to store text?

#The length of char is fixed, and the length of varchar and text is variable. (char may waste space, and the string length is not enough, then use spaces to supplement the empty string)

Char and varchar can set default values, but text has no default value.

The length must be specified when defining char and varchar. You usually do not need to specify the length when defining text, you can calculate it yourself.

CHAR and VARCHAR types

CHAR(M) is a fixed-length string, and the string column length is specified when defining. When saved, pads spaces on the right to the specified length. M represents the length of the column, ranging from 0 to 255 characters.

For example, CHAR(4) defines a fixed-length string column containing a maximum of 4 characters. When a CHAR value is retrieved, trailing spaces are removed.

VARCHAR(M) is a variable-length string, M represents the length of the maximum column, and the range of M is 0~65535. The maximum actual length of a VARCHAR is determined by the size of the longest line and the character set used, while the actual space occupied is the actual length of the string plus one.

For example, VARCHAR(50) defines a string with a maximum length of 50. If the inserted string has only 10 characters, the actual stored string will be 10 characters and an end-of-string character. VARCHAR trailing spaces are preserved when values ​​are saved and retrieved.

TEXT type

TEXT column stores non-binary strings, such as article content, comments, etc. Trailing spaces are not removed when saving or querying TEXT column values.

TEXT types are divided into 4 types: TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT. Different TEXT types have different storage spaces and data lengths.

TINYTEXT represents a TEXT column with a length of 255 (28-1) characters.

TEXT represents a TEXT column with a length of 65535 (216-1) characters.

MEDIUMTEXT represents a TEXT column with a length of 16777215 (224-1) characters.

LONGTEXT represents a TEXT column with a length of 4294967295 or 4GB (232-1) characters.

The above is the detailed content of What does mysql use to store text?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template