Home  >  Article  >  Database  >  搞定MySQL数据库中文模糊检索问题_MySQL

搞定MySQL数据库中文模糊检索问题_MySQL

WBOY
WBOYOriginal
2016-06-01 14:04:31882browse

在 MySQL下,在进行中文模糊检索时,经常会返回一些与之不相关的记录,如查找 "%a%" 时,返回的可能有中文字符,却没有a字符存在。本人以前也曾遇到过类似问题,经详细阅读MySQL的Manual,发现可以有一种方法很方便的解决并得到满意的结果。 (m?]sPEA`a  
@@)V/fia  
  例子: jLihNH?R}  
B]|0dP;  
  希望通过“标题”对新闻库进行检索,关键字可能包含是中英文,如下SQL语句: 2WXj>&d  
"T eLa |n  
QUOTE: !7"F`UE~>  
select id,title,name from achech_com.news where title like '%a%' 1$|CVhBb%  
pBW66B1h  
:@AB/\  
  返回的结果,某些title字段确定带了“a”关键字,而有些则只有中文,但也随之返回在检索结果中。 at*5je  
yUg/^Q  
  解决方法,使用 BINARY 属性进行检索,如: )M#[w''=  
^" ';f|  
QUOTE: )g4wt[=_+  
select id,title,name from achech_com.news where binary title like '%a%' )NyFPh  
{S

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn