Home >Database >Mysql Tutorial >How many bytes does a Chinese character occupy in MySQL?
In mysql, if it is under the latin1 character set, one Chinese character occupies 2 bytes; if it is under the utf8 character set, one Chinese character occupies 3 bytes; if it is under the gbk character set , one Chinese character occupies 2 bytes.
(Recommended tutorial: mysql video tutorial)
Chinese characters in each character set of mysql and the number of bytes occupied by letters
varchar(N), where N refers to the number of characters, not the number of bytes. The number of bytes occupied is related to the encoding
The test under mysql 5.1.5-alpha came to the following conclusion
latin1:
1character=1byte , 1 Chinese character = 2 character,
That is to say, if a field is defined as varchar(200), it can store 100 Chinese characters or 200 letters.
This should be noted, especially when the field content is composed of letters and Chinese characters, try to assume that the field content is composed of Chinese characters, and set the field length accordingly
utf8:
1character=3bytes, 1 Chinese character=1character
That is to say, if a field is defined as varchar(200), it can store 200 Chinese characters or 200 letters.
gbk:
1character=2bytes,1 Chinese character=1character
That is to say, if a field is defined as varchar(200), it can be stored 200 Chinese characters or 200 letters.
The above is the detailed content of How many bytes does a Chinese character occupy in MySQL?. For more information, please follow other related articles on the PHP Chinese website!