索引设计原则
字段内容需要足够花样
性别不适合做索引
全文索引
Mysql5.5支持全文索引
全文索引不支持中文
--全文索引
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT
)engine=myisam charset=utf8;
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 ...');
alter table articles add fulltext index `index_content` (title,body);
没有使用全文索引
explain select * from articles where title like '%MySQL%'\G
使用全文索引match() against()
explain select * from articles where match(title,body) against ('MySQL,DataBase')\G