問題描述
我有一個(gè)帶有 utf8 通用 ci 排序規(guī)則的 MySQL 表.在表格中,我可以看到兩個(gè)條目:
I have a MySQL table with utf8 general ci collation. In the table, I can see two entries:
糟糕
廢話
我使用的查詢?nèi)缦滤?
I am using a query that looks like this:
SELECT * FROM `words` WHERE `word` = 'abád'
查詢結(jié)果給出了兩個(gè)詞:
The query result gives both words:
糟糕
廢話
有沒有辦法表明我只希望 MySQL 找到帶重音的單詞?我希望查詢只返回
Is there a way to indicate that I only want MySQL to find the accented word? I want the query to only return
廢話
我也試過這個(gè)查詢:
SELECT * FROM `words` WHERE BINARY `word` = 'abád'
它沒有給我任何結(jié)果.謝謝你的幫助.
It gives me no results. Thank you for the help.
推薦答案
如果您對該字段的搜索總是對重音敏感,則將該字段的排序規(guī)則聲明為 utf8_bin(這將比較 utf8-encoded 字節(jié))或使用特定于語言的排序規(guī)則來區(qū)分重音字符和非重音字符.
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
如果搜索通常不區(qū)分重音,但您想為此搜索設(shè)置例外,請嘗試;
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
這篇關(guān)于如何在 MySql 中進(jìn)行重音敏感搜索的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!