Mysql storage type length

Analysis of the data types MySQL

      MySQL There are several types of data may be limited type of "length", there CHAR (Length), VARCHAR (Length), TINYINT (Length), SMALLINT (Length), MEDIUMINT (Length), INT (Length), BIGINT (Length), FLOAT (Length, Decimals), DOUBLE (Length, Decimals) and DECIMAL (Length, Decimals).

      However, the length of these data types, not all referring to the data size. Specifically, that is to:
(1) the length of CHAR, VARCAHR is the length of a character, for example, CHAR [3] can only put the string "123", if the insertion data "1234", taken from the high, to "123" . VARCAHR empathy.

(2) the length TINYINT, SMALLINT, MEDIUMINT, INT and BIGINT, in fact, independent of the size of the data and! Length refers to the display width, for example: int (3) is shown as three digital memory 001 is shown as a 

 

As can be seen, the display width of 3 id, the left 0s insufficient, as it is longer than the data output. ZEROFILL If not, see if the display width, without leading zeros.

(3) the length of FLOAT, DOUBLE and DECIMAL refers to the total number of bits (including after the decimal point), e.g. DECIMAL (4,1) refers to the total number of digits is 4, one after the decimal point, if the insert 1234, the query data is 999.9. Follows

 


Appendix common MySQL data types (reserved memo)

 

Types of

Size

Description

CAHR(Length)

Length byte

Fixed-length field, a length of 0 to 255 characters

VARCHAR(Length)

String String length + length byte + 2 bytes or

Variable-length field, a length of from 0 to 65,535 characters.

TINYTEXT

String length + 1 byte

String with a maximum length of 255 characters

TEXT

String length byte + 2

String with a maximum length of 65 characters 535

MEDIUMINT

String length byte + 3

String with a maximum length of 16 777 215 characters

LONGTEXT

String length of 4 bytes

String with a maximum length of 4,294,967,295 characters

TINYINT(Length)

1 byte

Range: -128 to 127, or 0 to 255 (unsigned)

SMALLINT(Length)

2 bytes

Range: -32 768 to 32 767 or 65 535 0 ~ (unsigned)

MEDIUMINT(Length)

3 bytes

Range: -8388608 8388607 ~ or ~ 0 16777215 (unsigned)

INT(Length)

4 bytes

Range: ~ -2 147 483 648 2 147 483 647, or 0 to 4,294,967,295 (unsigned)

BIGINT(Length)

8 bytes

Range: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807, or 0-18 446,744,073,709,551 615 (unsigned)

FLOAT(Length, Decimals)

4 bytes

Having a smaller number of floating point

DOUBLE(Length, Decimals)

8 bytes

Having a large number of floating point

DECIMAL(Length, Decimals)

Length + 1 byte or bytes Length + 2

DOUBLE stored as a string, allowing for a fixed decimal point

DATE

3 bytes

Using YYYY-MM-DD format

DATETIME

8 bytes

Using YYYY-MM-DD HH: MM: SS format

TIMESTAMP

4 bytes

Using YYYYMMDDHHMMSS format; terminates in an acceptable range 2037

TIME

3 bytes

Using HH: MM: SS format

ENUM

1 or 2 bytes

Enumeration (enumeration) shorthand, which means that each column can have one of several possible values

SET

3, 4 or 8 bytes

And ENUM same, but each column can have multiple possible values

 

 

以上 转自 https://blog.csdn.net/DayDreamingBoy/article/details/6310907

Mysql文字长度限制TEXT、TINYTEXT、MEDIUMTEXT、LONGTEXT

 

有4种TEXT类型:TINYTEXT、TEXT、MEDIUMTEXT和LONGTEXT。这些对应4种BLOB类型,有相同的最大长度和存储需求。

 

BLOB是一个二进制大对象,可以容纳可变数量的数据。有4种BLOB类型:TINYBLOB、BLOB、MEDIUMBLOB和LONGBLOB。它们只是可容纳值的最大长度不同。

tinytext, tinyBlob: 最大长度255个字元(2^8-1)


text, Blob: 最大长度65535个字元(2^16-1)


mediumtext, mediumBlob: 最大长度 16777215 个字元(2^24-1)


longtext, longBlob: 最大长度4294967295个字元 (2^32-1)

Guess you like

Origin www.cnblogs.com/duidui-li/p/11483030.html