mysql中文专栏
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UTF-8 由 1 到 3 个字节的可变长度字符组成,UCS2 (UTF-16) 是每个字符固定 2 个字节。
我对汉字没有经验,但是这个问题的最佳答案很好地回答了基本问题: UTF-8 和 UTF-16 之间的区别?
从那里:
看来对于汉字来说,UCS-2倾向于节省存储空间。如果这是一个 Web 项目,我会倾向于使用 UTF-8,因为它是更广泛的编码,也是 Web 世界的标准。此处有关 UTF-8 的其他参数:UTF-16 应该被视为有害吗?
mySQL 参考:9.1.10。统一码支持
UTF-8 consists of variable length characters ranging from 1 to 3 bytes, UCS2 (UTF-16) is a fixed 2 bytes per character.
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:
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