Mysql-性能分析(profiling 工具)
说明
profiling 工具可以用来查看sql语句的执行时间,可以用来查看sql语句的详细执行过程
基本命令 1.查看profiling的开启情况,默认是不开启的,值是0,开启之后值是1。
select @@profiling;
2.启动profiling:
set @@profiling=1
3.关闭profiling
set @@profiling=0;
4.查看sql语句的执行时间
show profiles;
5.查看某个查询语句的详细过程
show profile for query 1;
使用示例
查看语句执行时间 mysql> select count(*) from user;
+----------+
| count(*) |
+----------+
| 88 |
+----------+
1 row in set (0.00 sec)
mysql> select count(1) from user;
+----------+
| count(1) |
+----------+
| 88 |
+----------+
1 row in set (0.00 sec)
mysql> show profiles;
+----------+------------+---------------------------+
| Query_ID | Duration | Query |
+----------+------------+---------------------------+
| 1 | 0.00023950 | select count(*) from user |
| 2 | 0.00024500 | select count(1) from user |
+----------+------------+---------------------------+
2 rows in set, 1 warning (0.01 sec)
查看某个语句详细过程 mysql> show profile for query 1;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000075 |
| checking permissions | 0.000006 |
| Opening tables | 0.000020 |
| init | 0.000014 |
| System lock | 0.000006 |
| optimizing | 0.000006 |
| statistics | 0.000015 |
| preparing | 0.000010 |
| executing | 0.000002 |
| Sending data | 0.000051 |
| end | 0.000004 |
| query end | 0.000007 |
| closing tables | 0.000007 |
| freeing items | 0.000008 |
| cleaning up | 0.000009 |
+----------------------+----------+
15 rows in set, 1 warning (0.00 sec)
结尾
这一个黑夜的孩子,沉浸于冬天,倾心死亡不能自拔,热爱着空虚而寒冷的乡村--《春天,十个海子》
本文由 张六六柒 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Feb 14, 2020 at 03:58 am