mysql中文专栏

发布于 2024-10-13 14:12:59 字数 108 浏览 4 评论 0原文

mysql中存储汉字,建议存储为UTF8还是UCS2? (我正在使用 char 和 varchar)

此外,我还看到 UTF8 使用 4 个字节的数据来存储值。 UCS2 使用了多少个?

To store chinese characters in mysql, is it recommended to store them as UTF8 or UCS2? (I am using char and varchar)

Also, I have seen that UTF8 uses 4 bytes of data to store values. How many does UCS2 use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒与心事 2024-10-20 14:12:59

我已经看到UTF8使用4个字节的数据来存储值。 UCS2 使用了多少个?

UTF-8 由 1 到 3 个字节的可变长度字符组成,UCS2 (UTF-16) 是每个字符固定 2 个字节。

mysql中存储汉字,建议存储为UTF8还是UCS2?

我对汉字没有经验,但是这个问题的最佳答案很好地回答了基本问题: UTF-8 和 UTF-16 之间的区别?

从那里:

大多数合理的字符,如拉丁文、西里尔文、中文、日文都可以用 2 个字节表示。除非确实需要外来字符,否则这意味着 UTF-16 的 16 位子集可以用作固定长度编码,从而加快索引速度。

看来对于汉字来说,UCS-2倾向于节省存储空间。如果这是一个 Web 项目,我会倾向于使用 UTF-8,因为它是更广泛的编码,也是 Web 世界的标准。此处有关 UTF-8 的其他参数:UTF-16 应该被视为有害吗?


mySQL 参考:9.1.10。统一码支持

I have seen that UTF8 uses 4 bytes of data to store values. How many does UCS2 use?

UTF-8 consists of variable length characters ranging from 1 to 3 bytes, UCS2 (UTF-16) is a fixed 2 bytes per character.

To store chinese characters in mysql, is it recommended to store them as UTF8 or UCS2?

I have no experience with chinese characters, but the top answer to this SO question answers the basic question quite nicely: Difference between UTF-8 and UTF-16?

From there:

Most reasonable characters, like Latin, Cyrillic, Chinese, Japanese can be represented with 2 bytes. Unless really exotic characters are needed, this means that the 16-bit subset of UTF-16 can be used as a fixed-length encoding, which speeds indexing.

it seems like for chinese characters, UCS-2 tends to save storage space. If this is for a web project, I would however tend to use UTF-8 because it is the more widespread encoding, and a standard in the web world. Additional arguments for UTF-8 here: Should UTF-16 be considered harmful?


mySQL Reference: 9.1.10. Unicode Support

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文