Home  >  Article  >  Database  >  MySQL全文索引 回避like 的低效

MySQL全文索引 回避like 的低效

WBOY
WBOYOriginal
2016-06-07 17:07:241019browse

一般的数据库搜索都是用的SQL的 like 语句,like 语句是不能利用索引的,每次查询都是从第一条遍历至最后一条,查询效率极其低下

为什么要用全文索引呢?

一般的数据库搜索都是用的SQL的 like 语句,like 语句是不能利用索引的,每次查询都是从第一条遍历至最后一条,查询效率极其低下。一般数据超过10万或者在线人数过多,like查询都会导致数据库崩溃。这也就是为什么很多程序都只提供标题搜索的原因了,因为如果搜索内容,那就更慢了,几万数据就跑不动了。

Mysql 全文索引是专门为了解决模糊查询提供的,可以对整篇文章预先按照词进行索引,搜索效率高,,能够支持百万级的数据检索。

全文索引的设置

1、系统设置:修改 my.ini (Linux 下是 my.cnf ) ,在 [mysqld] 后面加入一行“ft_min_word_len=1”,然后重启Mysql

2、库表加全文索引:

create fulltext index kn_index_1 on t_knowledge( KeyWord);

linux

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