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>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2125893/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql 查詢建表語句sqlMySql
- Mysql使用Profiling分析語句消耗MySql
- mysql查詢效率慢的SQL語句MySql
- mysql查詢語句MySql
- 在mysql查詢效率慢的SQL語句MySql
- SQL查詢語句 (Oracle)SQLOracle
- SQL server 查詢語句SQLServer
- sql查詢語句流程SQL
- SQL mother查詢語句SQL
- [Mysql 查詢語句]——查詢欄位MySql
- linux下開啟mysql慢查詢,分析查詢語句LinuxMySql
- mysql查詢語句集MySql
- MySQL查詢阻塞語句MySql
- Mysql之查詢語句MySql
- MySQL資料庫:7、SQL常用查詢語句MySql資料庫
- 找出Mysql查詢速度慢的SQL語句MySql
- SQL Server阻塞查詢語句SQLServer
- SQL查詢語句使用 (轉)SQL
- sql 查詢經典語句SQL
- mysql查詢語句5:連線查詢MySql
- [Mysql 查詢語句]——分組查詢group byMySql
- [Mysql 查詢語句]——查詢指定記錄MySql
- MySql常用30種SQL查詢語句優化方法MySql優化
- MySQL、Oracle和SQL Server的分頁查詢語句MySqlOracleServer
- mysql高階查詢語句MySql
- MySQL基礎查詢語句MySql
- postgresql dba常用sql查詢語句SQL
- SQL語句查詢表結構SQL
- SQL查詢語句精華文章(轉)SQL
- Mysql常用sql語句(20)- 子查詢重點知識MySql
- Mysql 資料庫 -------- SQL語句進階查詢 ------- 前部分MySql資料庫
- oracle、my sql、sql隨機查詢語句OracleSQL隨機
- 優化SQL查詢:如何寫出高效能SQL語句優化SQL
- 一條 SQL 查詢語句是如何執行的?SQL
- 使用sql語句查詢平均值,使用sql語句查詢資料總條數, not in 篩選語句的使用SQL
- MySQL內連線查詢語句MySql
- MySQL的簡單查詢語句MySql
- mysql dba常用的查詢語句MySql