utf8_general_ci数据应该如何存储?
我正在使用 utf8_general_ci,数据应该如何存储?
我的意思是,如果我有一个 varchar/text 包含特殊字符,例如 áéíóúàèìòùçÇÀÉÌÒ,它们是这样存储的还是以某种方式转换?我正在进行大小写/重音不敏感搜索,但人们告诉我,我没有正确存储数据,所以我需要一个参考,
对此感到困惑,甚至我的 ORDER BY 也不起作用,因为数据已损坏(之后我知道数据应该如何存储,我要转换我的数据库,表/集名称已经是 utf8_general_ci / utf8)
i'm using utf8_general_ci, how should data be stored?
i mean like if i have a varchar/text that contains special chars like áéíóúàèìòùçÇÀÉÌÒ, they are stored like that or they are converted in some way? im making a CASE/ACCENT INSENSITIVE search, but people told me i wasnt properply storing data, so i need a reference
so confused about this, even my ORDER BY is not working because the data is broken (after i know how data should be store im going to convert my database, the tables/setnames are already utf8_general_ci / utf8)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只要妥善保存即可。 :)
说真的:您应该存储它,以便当您通过 phpMyAdmin 或 HeidiSQL 等程序中的 UTF-8 编码连接查看 UTF-8 编码数据库时,您可以看到实际的字符
áéíóúàèìòùçÇÀÉÌÒ
。仅此而已。utf8_general_ci
已经不区分重音,因为如果您使用 LIKE 子句
columnname LIKE "searchterm"
而不是columnname = "searchterm"
,它也会不区分大小写。Just store it properly. :)
Seriously: You should store it so that, when you view the UTF-8 encoded database through an UTF-8 encoded connection in a program like phpMyAdmin or HeidiSQL, you see the actual characters
áéíóúàèìòùçÇÀÉÌÒ
. Nothing more to it.utf8_general_ci
is already accent insensitive in thatif you use a LIKE clause
columnname LIKE "searchterm"
instead ofcolumnname = "searchterm"
, it will also be case insensitive.您确定数据已损坏吗?当你从表格中检索它时,所有的重音符号都丢失了吗? UTF-8是字符集,utf8_general_ci是排序规则。他们是不同的。如果您希望 ORDER BY 真正正确排序,您可能需要使用 utf8_unicode_ci 代替。排序主要是指查找和排序,而不是存储。
你能发布你的 SHOW CREATE TABLE 结果吗?
Are you sure the data is broken? When you retrieve it from the table, are all the accents missing? UTF-8 is a character set, utf8_general_ci is a collation. They're are different. If you want your ORDER BY to truly sort correctly, you may want to use utf8_unicode_ci instead. Collation is mainly in reference to searching and sorting, not storing.
Can you post your SHOW CREATE TABLE result?