MySQL supported string data types

Source: Internet
Author: User

is the 5.0 version of the character type in MySQL

String type

Bytes

Description and storage requirements

CHAR (M)

M

M is an integer between 0~255

VARCHAR (M)


M is an integer between 0~65535, the length of the value + 1 bytes

Tinyblob


Allowed length 0~255 bytes, value length + 1 bytes

Blob


Allowed length 0~65535 bytes, value length + 2 bytes

Mediumblob


Allowed length 0~167772150 bytes, value length + 3 bytes

Longblob


Allowed length 0~4294967295 bytes, value length + 4 bytes

Tinytext


Allowed length 0~255 bytes, value length + 2 bytes

TEXT


Allowed length 0~65535 bytes, value length + 2 bytes

Mediumtext


Allowed length 0~167772150 bytes, value length + 3 bytes

Longtext


Allowed length 0~4294967295 bytes, value length + 4 bytes

VARBINARY (M)


A variable-length byte string that allows a length of 0~m bytes, and a value of 1 bytes

BINARY (M)

M

A fixed-length byte string that allows a length of 0~m bytes

1. char and varchar types

At the time of retrieval, the CHAR column removes trailing spaces, while varchar preserves them. For example, the following:

Data types supported by MySQL--string type-Sandy-Sandy

2. Binary and varbinary are similar to char and varchar, but differ in that they contain binary strings and do not contain non-binary strings. Examples are as follows:

Data types supported by MySQL--string type-Sandy-Sandy

It can be found that when the binary value is saved, at the end of the value, by populating "ox00" (0 bytes) to reach the specified field definition length.

3. The enum Chinese name is called an enumeration type, and its value range needs to be specified by enumeration when the table is created, an enumeration of 1~255 members requires 1 bytes of storage, and 2 bytes for 255~65535 members. A maximum of 65,535 members are allowed. Examples are as follows:

Data types supported by MySQL--string type-Sandy-Sandy

From the above example, we can see that the enum type is ignored size, the ' m ', ' f ' in the storage of the time they are all capitalized, also can be seen to insert the value not within the specified scope of the enum, and did not return a warning, but inserted the enum (' m ', ' F ') the first value ' m ', Pay special attention to this point.

In addition, the enum type allows only a single value to be picked from a collection of values, not multiple values at a time.

4. Set type

The set is very similar to the enum type and is a string object that can contain 0~64 members. Depending on the member, the storage is also different.

10%-80% members of the collection, accounting for 1 bytes

Collection of 9~16成, accounting for 2 bytes

Collection of 17~24成, accounting for 3 bytes

Collection of 25~32成, accounting for 4 bytes

Collection of 33~64成, accounting for 5 bytes

The main difference between set and enum in addition to storage is that the set type can pick multiple members at a time, whereas an enum can only select one.

Examples are as follows:

Data types supported by MySQL--string type-Sandy-Sandy

The set type can be combined by selecting any 1 or more elements from the allowed values collection, so the input value can be injected correctly into the set type's column as long as it is within the combined range of allowed values. Values that exceed the allowable range of values such as (' a,v ') will not be allowed to be injected into the set type column in the above example, whereas for (' A,d,a ') A collection containing duplicate members will be taken only once, and the result of the write is "A,d"

MySQL supported string data types

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.