show global status like 'Com_______';
记录执行时间超过预设时间的语句。
//查看开启情况
show variables like 'slow_query_log';
修改目录下的配置文件
vi /etc/my.cnf
slow_query_log=1
long_query_time=2
systemctl restart mysqld
cat localhost-slow.log
//实时查询日志添加的内容
tail -f localhost-slow.log
了解每条sql语句耗时。
having_profiling参数
//是否支持
select @@having_profiling
//开启
set profiling=1;
select @@profiling;
//查看sql执行耗时
show profiles;
//指定query_id语句在各个阶段耗时情况
show profile for query 16;
show profile cpu for query 16;
执行计划

select查询的序列号 id越大,越先执行。
性能从好到差 null/system/const/eq_ref/ref/range
ref 非唯一索引
const 唯一索引
标识select的类型
显示可能应用在这张表上的索引
索引中使用到的字节数
实际使用的索引
估计要执行的查询行数
返回结果的行数占需求的百分比
未建立索引,查看效率
select * from tb_sku where id=1\G;
select * from tb_sku where sn="jjjj33223";
主键默认建立主键索引
针对字段创建索引
create index idx_sku_sn on tb_sku(sn);
为1000万数据构建b+树。
再次创建查询