Home > Database > Mysql Tutorial > How many bytes does a Chinese character occupy in MySQL?

How many bytes does a Chinese character occupy in MySQL?

青灯夜游
Release: 2020-10-21 15:04:04
Original
8671 people have browsed it

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.

How many bytes does a Chinese character occupy in MySQL?

(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!

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