这两个查询给了我完全相同的结果:
select * from topics where name='Harligt';
select * from topics where name='Härligt';
这怎么可能?似乎 mysql 在搜索时将 åäö 翻译为 aao。有什么办法可以关闭它吗?
据我所知,我在任何地方都使用 utf-8 编码。终端和php都会出现同样的问题。
最佳答案
是的,这是非语言特定的 unicode 排序规则中的标准行为。
9.1.13.1. Unicode Character Sets
To further illustrate, the following equalities hold in both utf8_general_ci and utf8_unicode_ci (for the effect this has in comparisons or when doing searches, see Section 9.1.7.7, “Examples of the Effect of Collation”):
Ä = A Ö = O Ü = U
另见 Examples of the effect of collation
你需要
使用不具有此“功能”的排序规则(即
utf8_bin
,但会产生其他后果)使用不同的排序规则仅用于查询。这应该有效:
select * from topics where name='Harligt' COLLATE utf8_bin;
如果你想做一个不区分大小写的 LIKE
但 not 有 Ä = A
元音变音转换,这将变得更加困难。我知道没有不区分大小写且不进行这种隐式变音符号转换的 mySQL 排序规则。如果有人知道,我很想知道。
相关:
关于MySQL 将 ÅÄÖ 视为 AAO?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2607130/