MySQL 全文索引

2021-10-09 17:22:01 字數 1897 閱讀 1100

全文索引主要對字串型別建立基於分詞的索引,主要是基於char、varchar和text的字段上,以便能夠更加快速地查詢資料量較大的字串型別的字段。全文索引以詞為基礎的,mysql預設的分詞是所有非字母和數字的特殊符號都是分詞符。mysql從3.23.23版本開始支援全文索引,mysql5.6以前只能在儲存引擎為myisam的資料表上建立全文索引,5.6之後innodb開始支援全文索引(5.7之後支援中文全文索引) 。在預設情況下,全文索引的搜尋執行方式為不區分大小寫,如果全文索引所關聯的字段為二進位制資料型別,就以區分大小寫的搜尋方式執行。

英文分詞索引

建立表同時新增全文索引fulltext index

create

table class(id int

, name varchar

(128

)unique

,teacher varchar(68

),comment

varchar

(1024

), fulltext index index_comment(

comment))

;

select

*from class where

match

(comment

) against (

'zhang'

);

show

create

table class;

explain

select

*from class where

match

(comment

) against (

'此班主任畢業自唐僧系'

);

中文分詞索引

建立表同時新增全文索引fulltext index

create

table class(id int

, name varchar

(128

)unique

, teacher varchar(64

),comment

varchar

(1024

),fulltext index index_des(

comment

)with parser ngram)

;

插入資料

insert

into class values(1

,'1班'

,'martin'

,'我是乙個兵,來自老百姓!');

insert

into class values(2

,'2班'

,'rock'

,'此班主任畢業自唐僧系');

insert

into class values(3

,'3班'

,'janny'

,'i'

'm miss zhang'

);

查詢資料

select

*from class where

match

(comment

) against(

'百姓'

);

方式一:create 語句

方式二:alter table 語句

中文索引配置(配置完後要重啟)

[mysqld]

ngram_token_size=2

中文切詞2個和兩個以上皆可

mysql全文索引的坑 MySQL全文索引問題

我有乙個包含以下資料的 文章 mysql select from articles id title body 1 mysql tutorial dbms stands for database 2 how to use mysql well after you went through a 3 o...

mysql全文索引

了解 solr 之後 發現全文索引也能做檢索 故了解了下 筆記如下 建立全文索引 alter table table add fulltext index fulltext table 列1 列2 查詢方式 select from table where match 列1 列2 against 查詢...

mysql全文索引

舊版的mysql的全文索引只能用在myisam 的char varchar和text的字段上。不過新版的mysql5.6.24上innodb引擎也加入了全文索引,所以具體資訊要隨時關注官網,create table article id int auto increment not null pri...