A Chinese character accounts for several bytes in mysql.
Editor to share with you a Chinese character in mysql accounts for a few bytes, I believe that most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
In mysql, in the case of latin1 character set, one Chinese character accounts for 2 bytes; in the case of utf8 character set, one Chinese character accounts for 3 bytes; in the case of gbk character set, one Chinese character accounts for 2 bytes.
Chinese characters and letters occupy the number of bytes under each character set of mysql
Varchar (N), where N refers to the number of characters, not bytes. The number of bytes occupied is related to encoding
The test under mysql 5.1.5-alpha draws the following conclusions.
Latin1:
1character=1byte, 1 Chinese character = 2character
In other words, if a field is defined as varchar, 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
In other words, if a field is defined as varchar, it can store 200 Chinese characters or 200 letters.
Gbk:
1 Chinese character = 1character
In other words, if a field is defined as varchar, it can store 200 Chinese characters or 200 letters.
The above is all the content in mysql where a Chinese character accounts for several bytes. Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!