MySQL优化分析
MySQL 单值索引:即一个索引只包含单个列,一个表可以有多个单列索引 唯一索引:索引列的值必须唯一,但允许有空值 主键索引:设定为主键后数据库会自动建立索引,innodb为聚簇索引 复合索引:即一个索引包含多个列 数据库慢主要体现在两方面:检索慢、排序慢 检索慢:大规模io,可以用linux命令 iostat -d 2 3 来查看。 排序慢:排序慢导致CPU消耗,可以使用linux命令 iostat -c 2 3 来查看。 故而,数据库慢,要么是IO慢,要么是CPU慢。(导致数据库慢的硬件层次上就这两个因素) 建立索引一定要注意:一张表的索引最多最多建立5个。 单值索引: create index idx_user_name on user(name); create index idx_user_weixin on user(weixin); 唯一索引: 索引列的值必须唯一,但允许有空值。 create unique index unique_idx_user_weixin on user(weixin); 复合索引: create index idx_user_name_age on user(name,age); 5.Explain explain sql语句之后会出现一个表,该表共有10个字段,分别为: id,select_type,table,type,possible