淮安市住房和城乡建设局网站首页,怎么找网站建设公司,崇文网站建设,竞价广告代运营SQL执行频次 语法#xff1a; SHOW GLOBAL STATUS LIKE COM_类型;
COM_insert; 插入次数
com_delete; 删除次数
com_update; 更新次数
com_select; 查询次数
com_______; 注意#xff1a;通过语法#xff0c;可以查询到数据库的实际状态#xff0c;就可以知道数据库是以增删…SQL执行频次 语法 SHOW GLOBAL STATUS LIKE COM_类型;
COM_insert; 插入次数
com_delete; 删除次数
com_update; 更新次数
com_select; 查询次数
com_______; 注意通过语法可以查询到数据库的实际状态就可以知道数据库是以增删改为主还是以查询为主如果是以查询为主就可以考虑sql 的索引优化。
慢查询日志(可以根据此日志看是否需要优化sql) 概述慢查询日志记录了超过指定时间的查询sql指定参数long_query_time,单位是秒默认值是10秒 如何查看慢查询功能是否打开 show variables like slow_query_log;参数说明 slow-query-log1 代表开启 0 代表关闭long_query_time10 代表慢查询超过10秒日志会记录slow_query_log_file 慢查询的日志文件 演示慢查询 把慢查询打开 slow-query-log1把慢查询时间设置段 1秒 long_query_time1重启一下mysql 的服务 分析慢查询日志 当sql 出现到慢查询日志中的时候就可以考虑对这条sql 进行优化了。
Profile 详情 概述show profiles 能够用来做SQL优化时协助我们了解时间消耗 查看Profile 是否开启 select profiling;设置profile开启 set [session/global] profiling1同过profile了解时间消耗 select * from user;
select count(*) from user;
select * from user where id 10;
select * from user where name 荆轲使用profiles文件观察时间消耗 show profiles;(每次执行query_id 都会变) show profile for query query_id;(注意query_id 是使用showprofiles 查询出来的) show profile cpu for query query_id;可以查询cpu占用
explain
explain 或者 desc 都可以获取select语句的查询信息语法explain 查询语句演示 id 执行先后的 explain select * from emp where dept_id (select id from dept where name 研发部)演示 type(const 使用主键或者唯一索引的时候) explain select id from dept where name 研发部; allexplain select * from emp where id 1;explain select * from user where phone 13508895543 key 演示 explain select * from user where id 5索引效率验证 添加主键索引添加的时候需要维护索引数据所以速度较慢 没有主键索引的时候耗时情况 添加了主键索引的时候耗时情况 给 name 字段添加索引列 name 没有添加索引列的时候 给name 添加了索引列之后
结论索引确实能提升查询速度而且是质的提升。