MySQL 索引设计原则

索引设计原则

字段内容需要足够花样

性别不适合做索引

全文索引

Mysql5.5支持全文索引 


MySQL 索引设计原则_第1张图片

全文索引不支持中文

--全文索引

CREATE TABLE articles (

      id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,

      title VARCHAR(200),

      body TEXT

)engine=myisam charset=utf8;


MySQL 索引设计原则_第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 ...');

alter table articles add fulltext index `index_content` (title,body);


MySQL 索引设计原则_第3张图片

没有使用全文索引

explain select * from articles where title like '%MySQL%'\G


MySQL 索引设计原则_第4张图片

使用全文索引match()  against()

explain select * from articles where match(title,body) against ('MySQL,DataBase')\G


MySQL 索引设计原则_第5张图片

你可能感兴趣的:(MySQL 索引设计原则)