本篇文章给大家带来的内容是关于mysql使用profile分析sql开销的代码,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
mysql使用profile分析sql开销
1.使用之前先查看当前数据库的版本信息,低版本无法使用. show version(); 或者 show variables like '%version%'2.查看profiling show variables like '%profil%' ; result: +------------------------+-------+ | variable_name | value | +------------------------+-------+ | have_profiling | yes | --只读变量,用于控制是否由系统变量开启或禁用profiling | profiling | off | --开启sql语句剖析功能 | profiling_history_size | 15 | --设置保留profiling的数目,缺省为15,范围为0至100,为0时将禁用p show profiles; 查看是否开启,效果同上.3.查看使用说明 help profile;4.开启profile set profiling=1; 赋值时候不要有多余的空格.5.运行sql,查看对应的profile select * from test ; show profiles; result: +----------+------------+--------------------------------------------------------------------------------------------------------------------------+ | query_id | duration | query | +----------+------------+--------------------------------------------------------------------------------------------------------------------------+ | 28 | 0.00033575 | select * from test | +----------+------------+--------------------------------------------------------------------------------------------------------------------------+ 分析sql性能,分析的时候可以加上对应的开销字段 show profile [cpu,io][all] for query 28 ; show profile for query 28 ; +----------------------+----------+ | status | duration | +----------------------+----------+ | starting | 5.7e-5 | | checking permissions | 7e-6 | | opening tables | 1.7e-5 | | init | 2.3e-5 | | system lock | 8e-6 | | optimizing | 5e-6 | | statistics | 1.1e-5 | | preparing | 9e-6 | | executing | 3e-6 | | sending data | 8.8e-5 | | end | 5e-6 | | query end | 6e-6 | | closing tables | 5e-6 | | freeing items | 7.8e-5 | | cleaning up | 1.5e-5 | +----------------------+----------+6.关闭 set profiling=off;
以上就是mysql使用profile分析sql开销的代码的详细内容。