本文介绍了如何在MySql中进行口音敏感搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有utf8常规ci排序规则的MySQL表.在表中,我可以看到两个条目:

I have a MySQL table with utf8 general ci collation. In the table, I can see two entries:

阿巴德
阿巴德

abad
abád

我正在使用如下查询:

SELECT *  FROM `words` WHERE `word` = 'abád'

查询结果给出两个词:

阿巴德
阿巴德

abad
abád

是否有一种方法可以表明我只希望MySQL查找带有重音的单词?我希望查询仅返回

Is there a way to indicate that I only want MySQL to find the accented word? I want the query to only return

abád

我也尝试过以下查询:

SELECT *  FROM `words` WHERE BINARY `word` = 'abád'

没有任何结果.谢谢您的帮助.

It gives me no results. Thank you for the help.

推荐答案

如果在该字段上的搜索始终对重音敏感,则将该字段的排序规则声明为utf8_bin(这将对utf8进行相等性比较) -encoded字节)或使用语言特定的归类,以区分带重音和不带重音的字符.

If your searches on that field are always going to be accent-sensitive, then declare the collation of the field as utf8_bin (that'll compare for equality the utf8-encoded bytes) or use a language specific collation that distinguish between the accented and un-accented characters.

col_name varchar(10) collate utf8_bin

如果搜索通常对重音不敏感,但您想对此搜索例外,请尝试;

If searches are normally accent-insensitive, but you want to make an exception for this search, try;

WHERE col_name = 'abád' collate utf8_bin

这篇关于如何在MySql中进行口音敏感搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 23:21