MySQL全文索引 迴避like 的低效

來源:互聯網
上載者:User

MySQL全文索引 迴避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);

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.