MySQL byte problem, Chinese and digital

Source: Internet
Author: User

Test under MySQL 5.1.5-alpha to the conclusion

Latin1:

1character=1byte, 1 kanji =2character,

In other words, a field is defined as varchar (200), it can store 100 characters or 200 letters.

This should be noted, especially when the field content is composed of letters and Chinese characters, as far as possible to assume that the field content is composed of Chinese characters, set the field length accordingly

UTF8:

1character=3bytes, 1 Kanji =1character

In other words, a field is defined as varchar (200), it can store 200 characters or 200 letters.

Gbk

1character=2bytes,1 Kanji =1character

In other words, a field is defined as varchar (200), it can store 200 characters or 200 letters.

The number type calculates the range represented by the number of bytes  tinyint                         &NBSP ;          1 byte  smallint                                 2 bytes  mediumint                 &N Bsp            3 bytes  int                   &NB Sp                       4 bytes  integer       &NBSP ;                           4 bytes  bigint                                     &NBSP;8 Bytes  float (X)                                 &NBSp;4 if X < = 24 or 8 If < = X < = 53 float                                       4 bytes  double                                    8 bytes  double PRECISION &nb Sp                8 bytes  real               &N Bsp                         8 bytes  decimal (m,d)                          m byte (d+2, if M < D)  numeric (m,d)                          m byte (d+2, if M < D)    date and time Type Date                                 &NB Sp   &NBSP  3 bytes  datetime                           &NBSP ;     8 bytes  timestamp                         &NB Sp     4 bytes  time                           & nbsp             3 bytes  year                   & nbsp                     1 byte    string type char (M)       &N Bsp                                m byte, 1 <= M <= 255 varchar (m)                           &N Bsp     l+1 bytes, in this L <= m and 1 <= m <= 255 tinyblob, Tinytext           &NBsp         l+1 byte, in this l< 2 ^ 8 blob, TEXT                                   l+2 byte, in this l< 2 ^ 16 mediumblob, Mediumtext   & nbsp     L+3 Byte, in this l< 2 ^ 24 longblob, longtext                 L+4 word section, in this l< 2 ^ 32 enum (' value1 ', ' value2 ',...)                1 or 2 bytes, depending on the enumeration Number of values (maximum value 65535)  set (' value1 ', ' value2 ',...)                    1,2, 3,4 or 8 bytes, depending on the number of members of the collection (up to 64 members)   where: 1. bit: bit
One binary data 0 or 1, is 1bit;
2. Byte: Byte
The basic unit of measurement for storage space, such as: the definition of VARCHAR (45) in MySQL means 45 bytes;
1 byte = 8 bit
3. A single byte of an English character;
1 letter = 1 byte = 8 bit
4. A kanji account of 2 bytes;
1 Kanji = 2 byte = + bit
BYTE: one byte (8 bits) ( -128~127) (-2 of 7 to 2 of 7) (1)
Short: two bytes (16 bits) ( -32768~32767) (-2 15 to 2 15)
Int: four bytes (32 bits) (one word length) ( -2147483648~2147483647) (-2 31 to 2 31)
Long: Eight bytes (64 bits) ( -9223372036854774808~9223372036854774807) (-2 of 63 parties to 2 63)-1
Float: four bytes (32 bits) (3.402823e+38 ~ 1.401298e-45) (e+38 is multiplied by 10 38, e-45 is multiplied by 10 minus 45 times)
Double: eight bytes (64 bits) (1.797693e+308~ 4.9000000e-324

MySQL byte problem, Chinese and digital

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.