mysql提供的可以用来分析当前会话语句执行资源消耗情况的命令profile.默认是关闭的。
have_profiling=YES表示当前版本支持 该功能,我们需要开启profile功能,
set profiling=1;来开启(当前会话关闭前,只需要执行一次)
执行一条SQL语句:
select *from t3;
通过 show profiles查看SQL运行结果。
show profiles;
+----------+------------+------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+------------------------------------------+
| 1 | 0.00203775 | show variables like '%profil%' |
| 2 | 0.00026875 | SELECT DATABASE() |
| 3 | 0.00055675 | show databases |
| 4 | 0.00013675 | show tables |
| 5 | 0.00194650 | show global variables like '%profiling%' |
| 6 | 0.00009400 | SELECT DATABASE() |
| 7 | 0.00017975 | show tables |
| 8 | 0.00030900 | select *from t3 |
| 9 | 0.00003700 | zzz~set profiling=1 |
+----------+------------+------------------------------------------+
9 rows in set, 1 warning (0.00 sec)
Query_ID 代表运行语句的编号,8代表执行select查询语句的编号。
通过show profile for query 8查看执行查询语句的资源消耗情况;
通过show profile bkick io,cpu for query 8查看消耗CPU和磁盘I/O的情况: