MySQL全文索引

全文索引(Fulltext)
MySQL全文索引
MySQL全文索引
全文索引 主要是应用于文本文件,全文索引针对MyISAM搜索引擎有效
1:创建表
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) engine=myisam charset=utf8;
2:插入数据
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
3:查询索引
show index from articles\G
MySQL全文索引
MySQL全文索引
4:如何使用索引
MySQL全文索引
MySQL全文索引
1:错误用法:
select * from articles where body like‘%mysql%’; 【不会使用到全文索引】
2:证明:
explain select * from articles where body like ‘%mysql%'\G
MySQL全文索引
MySQL全文索引
3:正确用法
SELECT * FROM articles
WHERE MATCH (title,body) AGAINST ('database');
MySQL全文索引
MySQL全文索引
5:全文索引的注意点
1:在mysql中的FULLTEXT全文索引中只对MyISAM搜索引擎生效
2:目前只针对英文生效,需要使用splinx(coreseek中文版)技术处理中文
3:全文索引一个叫停止词,  因为在一个文本中,创建索引是一个无穷大的数,因此,对一些常用词和字符,就不会创建,这些词,称为停止词.