mysql> select version();
-- profile默认是不打开的
mysql> show profiles;
Empty set (0.02 sec)
-- 验证修改后的结果
mysql> show variables like "%pro%";
-- 可以看到profiling 默认是OFF的。
-- 开启profile
mysql> set profiling=1;
mysql> select * from test;
+------------+---------------------+-------------+----------------------------------+-----------------+-------
| company_id | insert_time | update_time | s_info_compname | s_info_compcode |
+------------+---------------------+-------------+----------------------------------+-----------------+-------
| 13547 | 2020-11-16 22:45:00 | NULL | 泰兴市城市投资发展集团有限公司 | 3k2OWBLoYh
| 13548 | 2020-11-16 22:45:00 | NULL | 昆明市晋宁区国有资本运营有限公司 | 792890354
+------------+---------------------+-------------+----------------------------------+-----------------+-------
mysql> show profiles;
+----------+------------+----------------------------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+----------------------------------------------------------------+
| 1 | 0.00188625 | show variables |
| 2 | 3.660707 | select * from test |
+----------+------------+----------------------------------------------------------------+
-- 使用query_id查询 sql查询开销情况
mysql> show profile cpu,block io for query 2;
+----------------------+----------+----------+------------+--------------+---------------+
| Status | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+----------------------+----------+----------+------------+--------------+---------------+
| starting | 9.8E-5 | 0 | 0 | 0 | 0 |
| checking permissions | 1.5E-5 | 0 | 0 | 0 | 0 |
| Opening tables | 2.4E-5 | 0 | 0 | 0 | 0 |
| init | 4.6E-5 | 0 | 0 | 0 | 0 |
| System lock | 1.5E-5 | 0 | 0 | 0 | 0 |
| optimizing | 1.5E-5 | 0 | 0 | 0 | 0 |
| statistics | 2.6E-5 | 0 | 0 | 0 | 0 |
| preparing | 1.9E-5 | 0 | 0 | 0 | 0 |
| executing | 1E-5 | 0 | 0 | 0 | 0 |
| Sending data | 0.003407 | 0 | 0 | 0 | 0 |
| end | 1.5E-5 | 0 | 0 | 0 | 0 |
| query end | 1.6E-5 | 0 | 0 | 0 | 0 |
| closing tables | 1.9E-5 | 0 | 0 | 0 | 0 |
| freeing items | 5.8E-5 | 0 | 0 | 0 | 0 |
| cleaning up | 1.9E-5 | 0 | 0 | 0 | 0 |
+----------------------+----------+----------+------------+--------------+---------------+
15 rows in set
type:
ALL --显示所有的开销信息
BLOCK IO --显示块IO相关开销
CONTEXT SWITCHES --上下文切换相关开销
CPU --显示CPU相关开销信息
IPC --显示发送和接收相关开销信息
MEMORY --显示内存相关开销信息
PAGE FAULTS --显示页面错误相关开销信息
SOURCE --显示和Source_function,Source_file,Source_line相关的开销信息
SWAPS --显示交换次数相关开销的信息
MySQL show profile
最新推荐文章于 2022-09-14 15:55:21 发布