MySQL 处理 ÅÄÖ作为AAO?
这两个查询给了我完全相同的结果:
select * from topics where name='Harligt';
select * from topics where name='Härligt';
这怎么可能?似乎 mysql 在搜索时将 åäö 翻译为 aao 。有什么办法可以关掉这个吗?
据我所知,我到处都使用 utf-8 编码。终端和 php 都会出现同样的问题。
These two querys gives me the exact same result:
select * from topics where name='Harligt';
select * from topics where name='Härligt';
How is this possible? Seems like mysql translates åäö to aao when it searches. Is there some way to turn this off?
I use utf-8 encoding everywhere as far as i know. The same problem occurs both from terminal and from php.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是的,这是非特定于语言的 unicode 排序规则中的标准行为。
9.1.13.1。 Unicode 字符集
另请参见排序规则效果示例
您需要
使用不具有此“功能”的排序规则(即
utf8_bin
,但这会产生其他后果)仅针对查询使用不同的排序规则。这应该有效:
如果您想要执行不区分大小写的
LIKE
但不进行Ä = A
变音转换,则会变得更加困难。我知道没有任何 mySQL 排序规则是不区分大小写的,并且不会执行这种隐式变音转换。如果有人知道的话,我很想听听。相关:
Yes, this is standard behaviour in the non-language-specific unicode collations.
9.1.13.1. Unicode Character Sets
See also Examples of the effect of collation
You need to either
use a collation that doesn't have this "feature" (namely
utf8_bin
, but that has other consequences)use a different collation for the query only. This should work:
it becomes more difficult if you want to do a case insensitive
LIKE
but not have theÄ = A
umlaut conversion. I know no mySQL collation that is case insensitive and does not do this kind of implicit umlaut conversion. If anybody knows one, I'd be interested to hear about it.Related:
由于您在瑞典,我建议使用瑞典语排序规则。下面是一个显示其差异的示例:
请注意,在本示例中,我仅将一列更改为瑞典语排序规则,但您可能应该对整个数据库、所有表、所有 varchar 列执行此操作。
Since you are in Sweden I'd recommend using the Swedish collation. Here's an example showing the difference it makes:
Note that in this example I only changed the one column to Swedish collation, but you should probably do it for your entire database, all tables, all varchar columns.
虽然排序规则是解决此问题的一种方法,但在我看来,更直接的方法是
BINARY
关键字:将返回
1|0
在您的情况下:
另请参阅 https://www.w3schools.com/sql/func_mysql_binary.asp
While collations are one way of solving this, the much more straightforward way seems to me to be the
BINARY
keyword:will return
1|0
In your case:
See also https://www.w3schools.com/sql/func_mysql_binary.asp
您想要检查排序规则设置,排序规则是设置哪些字符相同的属性。
这两个页面应该可以帮助您
http://dev.mysql。 com/doc/refman/5.1/en/charset-general.html
http://dev.mysql.com/doc/refman/5.1/en/charset-mysql.html
you want to check your collation settings, collation is the property that sets which characters are identical.
these 2 pages should help you
http://dev.mysql.com/doc/refman/5.1/en/charset-general.html
http://dev.mysql.com/doc/refman/5.1/en/charset-mysql.html
在这里你可以看到一些整理图表。 http://collation-charts.org/mysql60/。我不确定哪个是使用的 utf8_general_ci 。
这是 utf8_swedish_ci 的图表。它显示它解释为相同的字符。 http://collation-charts.org/mysql60/mysql604.utf8_swedish_ci.html
Here you can see some collation charts. http://collation-charts.org/mysql60/. I'm no sure which is the used utf8_general_ci though.
Here is the chart for utf8_swedish_ci. It shows which characters it interprets as the same. http://collation-charts.org/mysql60/mysql604.utf8_swedish_ci.html