MySQL如何利用profiling分析SQL查询语句
发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,查看profiling是否开启:mysql> select @@profiling;+-------------+| @@profiling |+-------------+| 0 |+-------
千家信息网最后更新 2026年11月03日MySQL如何利用profiling分析SQL查询语句查看profiling是否开启:
mysql> select @@profiling;
+-------------+
| @@profiling |
+-------------+
| 0 |
+-------------+
1 row in set (0.00 sec)
开启profiling:
mysql> set profiling=1;
Query OK, 0 rows affected (0.00 sec)
mysql> select @@profiling;
+-------------+
| @@profiling |
+-------------+
| 1 |
+-------------+
1 row in set (0.00 sec)
执行若干条SQL查询:
mysql> use mysql
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| mysql |
+------------+
1 row in set (0.00 sec)
mysql> select host,user,Password from user limit 10;
+-----------+-----------------+-------------------------------------------+
| host | user | Password |
+-----------+-----------------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| % | chenfeng | *716E7D76E850A91A8311F35B6BFB1213B751F230 |
| % | test@localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| % | sa@localhost | *4D0DD2673C1DE57138354E81A957460B774C4BC2 |
| % | admin@localhost | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| localhost | dsf | *AFED783E50FCEF7B1C89AC89C6E1A0405BD7F313 |
| localhost | dsf1 | *98D1D8D997EA32BABDFEEC2EBB62BB6D010036C6 |
| % | dsf2 | *0007B182797FAD2A8A37C3F73A011BBD36C49857 |
+-----------+-----------------+-------------------------------------------+
8 rows in set (0.00 sec)
查询上述语句的Profiling情况:
mysql> show profiles;
+----------+------------+----------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+----------------------------------------------+
| 1 | 0.00012600 | select @@profiling |
| 2 | 0.00018450 | SELECT DATABASE() |
| 3 | 0.00011950 | select database() |
| 4 | 0.11296025 | show columns from user |
| 5 | 0.00038725 | select host,user,Password from user limit 10 |
+----------+------------+----------------------------------------------+
14 rows in set (0.00 sec)
查看Query_ID=5语句的I/O消耗情况:
mysql> show profile block io for query 5;
+--------------------------------+----------+--------------+---------------+
| Status | Duration | Block_ops_in | Block_ops_out |
+--------------------------------+----------+--------------+---------------+
| starting | 0.000018 | NULL | NULL |
| Waiting for query cache lock | 0.000003 | NULL | NULL |
| checking query cache for query | 0.000077 | NULL | NULL |
| checking permissions | 0.000009 | NULL | NULL |
| Opening tables | 0.000020 | NULL | NULL |
| System lock | 0.000014 | NULL | NULL |
| init | 0.000020 | NULL | NULL |
| optimizing | 0.000005 | NULL | NULL |
| statistics | 0.000011 | NULL | NULL |
| preparing | 0.000009 | NULL | NULL |
| executing | 0.000003 | NULL | NULL |
| Sending data | 0.000071 | NULL | NULL |
| end | 0.000004 | NULL | NULL |
| query end | 0.000002 | NULL | NULL |
| closing tables | 0.000011 | NULL | NULL |
| freeing items | 0.000101 | NULL | NULL |
| logging slow query | 0.000006 | NULL | NULL |
| cleaning up | 0.000004 | NULL | NULL |
+--------------------------------+----------+--------------+---------------+
18 rows in set (0.00 sec)
查看Query_ID=5语句的CPU消耗情况:
mysql> show profile cpu for query 5;
+--------------------------------+----------+----------+------------+
| Status | Duration | CPU_user | CPU_system |
+--------------------------------+----------+----------+------------+
| starting | 0.000018 | 0.000000 | 0.000000 |
| Waiting for query cache lock | 0.000003 | 0.000000 | 0.000000 |
| checking query cache for query | 0.000077 | 0.000000 | 0.000000 |
| checking permissions | 0.000009 | 0.000000 | 0.000000 |
| Opening tables | 0.000020 | 0.000000 | 0.000000 |
| System lock | 0.000014 | 0.000000 | 0.000000 |
| init | 0.000020 | 0.000000 | 0.000000 |
| optimizing | 0.000005 | 0.000000 | 0.000000 |
| statistics | 0.000011 | 0.000000 | 0.000000 |
| preparing | 0.000009 | 0.000000 | 0.000000 |
| executing | 0.000003 | 0.000000 | 0.000000 |
| Sending data | 0.000071 | 0.000000 | 0.000000 |
| end | 0.000004 | 0.000000 | 0.000000 |
| query end | 0.000002 | 0.000000 | 0.000000 |
| closing tables | 0.000011 | 0.000000 | 0.000000 |
| freeing items | 0.000101 | 0.000000 | 0.000000 |
| logging slow query | 0.000006 | 0.000000 | 0.000000 |
| cleaning up | 0.000004 | 0.000000 | 0.000000 |
+--------------------------------+----------+----------+------------+
18 rows in set (0.00 sec)
mysql>
mysql> select @@profiling;
+-------------+
| @@profiling |
+-------------+
| 0 |
+-------------+
1 row in set (0.00 sec)
开启profiling:
mysql> set profiling=1;
Query OK, 0 rows affected (0.00 sec)
mysql> select @@profiling;
+-------------+
| @@profiling |
+-------------+
| 1 |
+-------------+
1 row in set (0.00 sec)
执行若干条SQL查询:
mysql> use mysql
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| mysql |
+------------+
1 row in set (0.00 sec)
mysql> select host,user,Password from user limit 10;
+-----------+-----------------+-------------------------------------------+
| host | user | Password |
+-----------+-----------------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| % | chenfeng | *716E7D76E850A91A8311F35B6BFB1213B751F230 |
| % | test@localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| % | sa@localhost | *4D0DD2673C1DE57138354E81A957460B774C4BC2 |
| % | admin@localhost | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| localhost | dsf | *AFED783E50FCEF7B1C89AC89C6E1A0405BD7F313 |
| localhost | dsf1 | *98D1D8D997EA32BABDFEEC2EBB62BB6D010036C6 |
| % | dsf2 | *0007B182797FAD2A8A37C3F73A011BBD36C49857 |
+-----------+-----------------+-------------------------------------------+
8 rows in set (0.00 sec)
查询上述语句的Profiling情况:
mysql> show profiles;
+----------+------------+----------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+----------------------------------------------+
| 1 | 0.00012600 | select @@profiling |
| 2 | 0.00018450 | SELECT DATABASE() |
| 3 | 0.00011950 | select database() |
| 4 | 0.11296025 | show columns from user |
| 5 | 0.00038725 | select host,user,Password from user limit 10 |
+----------+------------+----------------------------------------------+
14 rows in set (0.00 sec)
查看Query_ID=5语句的I/O消耗情况:
mysql> show profile block io for query 5;
+--------------------------------+----------+--------------+---------------+
| Status | Duration | Block_ops_in | Block_ops_out |
+--------------------------------+----------+--------------+---------------+
| starting | 0.000018 | NULL | NULL |
| Waiting for query cache lock | 0.000003 | NULL | NULL |
| checking query cache for query | 0.000077 | NULL | NULL |
| checking permissions | 0.000009 | NULL | NULL |
| Opening tables | 0.000020 | NULL | NULL |
| System lock | 0.000014 | NULL | NULL |
| init | 0.000020 | NULL | NULL |
| optimizing | 0.000005 | NULL | NULL |
| statistics | 0.000011 | NULL | NULL |
| preparing | 0.000009 | NULL | NULL |
| executing | 0.000003 | NULL | NULL |
| Sending data | 0.000071 | NULL | NULL |
| end | 0.000004 | NULL | NULL |
| query end | 0.000002 | NULL | NULL |
| closing tables | 0.000011 | NULL | NULL |
| freeing items | 0.000101 | NULL | NULL |
| logging slow query | 0.000006 | NULL | NULL |
| cleaning up | 0.000004 | NULL | NULL |
+--------------------------------+----------+--------------+---------------+
18 rows in set (0.00 sec)
查看Query_ID=5语句的CPU消耗情况:
mysql> show profile cpu for query 5;
+--------------------------------+----------+----------+------------+
| Status | Duration | CPU_user | CPU_system |
+--------------------------------+----------+----------+------------+
| starting | 0.000018 | 0.000000 | 0.000000 |
| Waiting for query cache lock | 0.000003 | 0.000000 | 0.000000 |
| checking query cache for query | 0.000077 | 0.000000 | 0.000000 |
| checking permissions | 0.000009 | 0.000000 | 0.000000 |
| Opening tables | 0.000020 | 0.000000 | 0.000000 |
| System lock | 0.000014 | 0.000000 | 0.000000 |
| init | 0.000020 | 0.000000 | 0.000000 |
| optimizing | 0.000005 | 0.000000 | 0.000000 |
| statistics | 0.000011 | 0.000000 | 0.000000 |
| preparing | 0.000009 | 0.000000 | 0.000000 |
| executing | 0.000003 | 0.000000 | 0.000000 |
| Sending data | 0.000071 | 0.000000 | 0.000000 |
| end | 0.000004 | 0.000000 | 0.000000 |
| query end | 0.000002 | 0.000000 | 0.000000 |
| closing tables | 0.000011 | 0.000000 | 0.000000 |
| freeing items | 0.000101 | 0.000000 | 0.000000 |
| logging slow query | 0.000006 | 0.000000 | 0.000000 |
| cleaning up | 0.000004 | 0.000000 | 0.000000 |
+--------------------------------+----------+----------+------------+
18 rows in set (0.00 sec)
mysql>
语句
情况
查询
消耗
分析
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网金融科技
互联网新科技
互联网科技深圳
互联网科技革命
苏州互联网科技贷款公司
互联网科技公司做什么
互联网科技生活的内容
温州喔噻互联网科技有限公司
互联网金融中的现代科技
中国互联网十大科技股排名
爱医互联网络科技
互联网时代的科技公司
互联网安防科技感
上海万顺科技互联网有限公司招聘
互联网科技手抄报图片
互联网科技收购价值
广州三三互联网科技有限公司
安徽九吞吴互联网科技有限公司
知域互联网科技有限公司官网
颐高云石互联网科技
精品咖啡豆
互联网科技论坛
科技与互联网哪个更好
互联网科技和信息
如何创新互联网科技
互联网在线教育科技创业
华中科技大学互联网的牛人
上海乐五互联网科技有限公司
杭州科技互联网公司有哪些
如何强化互联网金融科技