查询索引
show index from tb_user
查看sql执行计划
explain select*from tb_user where id=10 or age=23
建立索引
create index idx_user_age on tb_user(age)
查看每条sql的耗时
show profiles;
查看指定语句的耗时
show profile for query 181
查看指定sql的cpu使用情况
show profile cpu for query 180
查看是否支持profile操作
select @@have_profiling
开启profiling
set profiling=1
查看语句类型的访问频次
show global status like'Com_______'
查看服务器状态信息
show status
查看不同email的数目
select count(distinct email)from tb_user
查看索引区分度
select count(distinct substring(email,1,6))/count(*) from tb_user
创建email前5个字符为索引
create index idx_email_5 on tb_user(email(5))
单列索引
联合索引
下面为覆盖索引,覆盖了主键,避免了回表查询