MySQL 将 ÅÄÖ 视为 AAO?

标签 mysql unicode encoding collation

这两个查询给了我完全相同的结果:

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;
    

如果你想做一个不区分大小写的 LIKEnotÄ = A 元音变音转换,这将变得更加困难。我知道没有不区分大小写且不进行这种隐式变音符号转换的 mySQL 排序规则。如果有人知道,我很想知道。

相关:

关于MySQL 将 ÅÄÖ 视为 AAO?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2607130/

相关文章:

javascript - 将数字签名上传到文件夹并提交到数据库

android - 如何将带有 Unicode 字符的字符串转换为普通字符串?

html - Unicode 在 Edge 中显示异常

mysql - 如何从 Outlook Express 更新 MySQL 数据库?

mysql - 权限问题

python - 将全角标点符号替换为正常宽度的等效字符

c# - 如何读取包含特殊字符的 ANSI 编码文件

Python UTF-8转换问题

text - UTF-8 字符串总是比 UTF-16 短吗?

php - 尝试上传图像并让它更新mysql