Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A Chinese character accounts for several bytes in mysql.

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 295

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report