MySQL 5.5 SHOW PROFILE、SHOW PROFILES語句介紹
SHOW PROFILE 和 SHOW PROFILES 語句顯示 MySQL 資料庫語句的資源消耗情況。
需要注意的是:這兩條命令均顯示當前會話的SQL資源消耗情況,不能顯示其他會話的資源消耗情況。
--需要開啟Profiling引數
mysql> show variables like 'profil%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| profiling | OFF |
| profiling_history_size | 15 |
+------------------------+-------+
2 rows in set (0.10 sec)
mysql> set profiling = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> show session variables like 'profil%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| profiling | ON |
| profiling_history_size | 15 |
+------------------------+-------+
2 rows in set (0.00 sec)
SHOW PROFILES顯示最近傳送到MySQL伺服器的語句。顯示語句的條數由profiling_history_size引數設定,預設值是15,最大值是100,將引數的值設為0並不會關閉profiling功能。除了SHOW PROFILE 和 SHOW PROFILES,其他的語句都會顯示在列表中。
SHOW PROFIL會顯示一條語句的具體資訊。如果沒有指定FOR QUERY語句,輸出結果會顯示最後執行的語句。如果指定了FOR QUERY和語句編號,則會顯示指定語句的資訊。語句編號對應SHOW PROFILES顯示結果中的Query_ID字段。LIMIT語句會限制輸出的行數。預設,SHOW PROFILE語句只顯示狀態和執行時間這兩個欄位,狀態欄位和SHOW PROCESSLIST裡面的狀態欄位相似。
--示例
mysql> select * from t9;
mysql> select * from t_arc1 limit 10;
mysql> show profiles;
+----------+------------+-------------------------------+
| Query_ID | Duration | Query |
+----------+------------+-------------------------------+
| 1 | 0.00019375 | select * from t9 |
| 2 | 0.00023150 | select * from t_arc1 limit 10 |
+----------+------------+-------------------------------+
2 rows in set (0.00 sec)
mysql> show profile for query 2;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000058 |
| checking permissions | 0.000005 |
| Opening tables | 0.000011 |
| System lock | 0.000006 |
| init | 0.000015 |
| optimizing | 0.000003 |
| statistics | 0.000011 |
| preparing | 0.000010 |
| executing | 0.000002 |
| Sending data | 0.000094 |
| end | 0.000003 |
| query end | 0.000003 |
| closing tables | 0.000003 |
| freeing items | 0.000007 |
| logging slow query | 0.000001 |
| cleaning up | 0.000002 |
+----------------------+----------+
16 rows in set (0.00 sec)
mysql> show profile cpu for query 2;
+----------------------+----------+----------+------------+
| Status | Duration | CPU_user | CPU_system |
+----------------------+----------+----------+------------+
| starting | 0.000058 | 0.000000 | 0.000000 |
| checking permissions | 0.000005 | 0.000000 | 0.000000 |
| Opening tables | 0.000011 | 0.000000 | 0.000000 |
| System lock | 0.000006 | 0.000000 | 0.000000 |
| init | 0.000015 | 0.000000 | 0.000000 |
| optimizing | 0.000003 | 0.000000 | 0.000000 |
| statistics | 0.000011 | 0.000000 | 0.000000 |
| preparing | 0.000010 | 0.000000 | 0.000000 |
| executing | 0.000002 | 0.000000 | 0.000000 |
| Sending data | 0.000094 | 0.000000 | 0.000000 |
| end | 0.000003 | 0.000000 | 0.000000 |
| query end | 0.000003 | 0.000000 | 0.000000 |
| closing tables | 0.000003 | 0.000000 | 0.000000 |
| freeing items | 0.000007 | 0.000000 | 0.000000 |
| logging slow query | 0.000001 | 0.000000 | 0.000000 |
| cleaning up | 0.000002 | 0.000000 | 0.000000 |
+----------------------+----------+----------+------------+
16 rows in set (0.00 sec)
--檢視SQL解析執行過程中每個步驟對應的原始碼的檔案、函式名以及具體的原始檔行數
MariaDB [test]> show profile source for query 31\G
*************************** 1. row ***************************
Status: starting
Duration: 0.000034
Source_function: NULL
Source_file: NULL
Source_line: NULL
*************************** 2. row ***************************
Status: checking permissions
Duration: 0.000005
Source_function: check_access
Source_file: sql_parse.cc
Source_line: 6043
需要注意的是:這兩條命令均顯示當前會話的SQL資源消耗情況,不能顯示其他會話的資源消耗情況。
--需要開啟Profiling引數
mysql> show variables like 'profil%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| profiling | OFF |
| profiling_history_size | 15 |
+------------------------+-------+
2 rows in set (0.10 sec)
mysql> set profiling = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> show session variables like 'profil%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| profiling | ON |
| profiling_history_size | 15 |
+------------------------+-------+
2 rows in set (0.00 sec)
SHOW PROFILES顯示最近傳送到MySQL伺服器的語句。顯示語句的條數由profiling_history_size引數設定,預設值是15,最大值是100,將引數的值設為0並不會關閉profiling功能。除了SHOW PROFILE 和 SHOW PROFILES,其他的語句都會顯示在列表中。
SHOW PROFIL會顯示一條語句的具體資訊。如果沒有指定FOR QUERY語句,輸出結果會顯示最後執行的語句。如果指定了FOR QUERY和語句編號,則會顯示指定語句的資訊。語句編號對應SHOW PROFILES顯示結果中的Query_ID字段。LIMIT語句會限制輸出的行數。預設,SHOW PROFILE語句只顯示狀態和執行時間這兩個欄位,狀態欄位和SHOW PROCESSLIST裡面的狀態欄位相似。
--示例
mysql> select * from t9;
mysql> select * from t_arc1 limit 10;
mysql> show profiles;
+----------+------------+-------------------------------+
| Query_ID | Duration | Query |
+----------+------------+-------------------------------+
| 1 | 0.00019375 | select * from t9 |
| 2 | 0.00023150 | select * from t_arc1 limit 10 |
+----------+------------+-------------------------------+
2 rows in set (0.00 sec)
mysql> show profile for query 2;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000058 |
| checking permissions | 0.000005 |
| Opening tables | 0.000011 |
| System lock | 0.000006 |
| init | 0.000015 |
| optimizing | 0.000003 |
| statistics | 0.000011 |
| preparing | 0.000010 |
| executing | 0.000002 |
| Sending data | 0.000094 |
| end | 0.000003 |
| query end | 0.000003 |
| closing tables | 0.000003 |
| freeing items | 0.000007 |
| logging slow query | 0.000001 |
| cleaning up | 0.000002 |
+----------------------+----------+
16 rows in set (0.00 sec)
mysql> show profile cpu for query 2;
+----------------------+----------+----------+------------+
| Status | Duration | CPU_user | CPU_system |
+----------------------+----------+----------+------------+
| starting | 0.000058 | 0.000000 | 0.000000 |
| checking permissions | 0.000005 | 0.000000 | 0.000000 |
| Opening tables | 0.000011 | 0.000000 | 0.000000 |
| System lock | 0.000006 | 0.000000 | 0.000000 |
| init | 0.000015 | 0.000000 | 0.000000 |
| optimizing | 0.000003 | 0.000000 | 0.000000 |
| statistics | 0.000011 | 0.000000 | 0.000000 |
| preparing | 0.000010 | 0.000000 | 0.000000 |
| executing | 0.000002 | 0.000000 | 0.000000 |
| Sending data | 0.000094 | 0.000000 | 0.000000 |
| end | 0.000003 | 0.000000 | 0.000000 |
| query end | 0.000003 | 0.000000 | 0.000000 |
| closing tables | 0.000003 | 0.000000 | 0.000000 |
| freeing items | 0.000007 | 0.000000 | 0.000000 |
| logging slow query | 0.000001 | 0.000000 | 0.000000 |
| cleaning up | 0.000002 | 0.000000 | 0.000000 |
+----------------------+----------+----------+------------+
16 rows in set (0.00 sec)
--檢視SQL解析執行過程中每個步驟對應的原始碼的檔案、函式名以及具體的原始檔行數
MariaDB [test]> show profile source for query 31\G
*************************** 1. row ***************************
Status: starting
Duration: 0.000034
Source_function: NULL
Source_file: NULL
Source_line: NULL
*************************** 2. row ***************************
Status: checking permissions
Duration: 0.000005
Source_function: check_access
Source_file: sql_parse.cc
Source_line: 6043
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2097692/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL SHOW 語句大全MySql
- MySQL 索引 效能分析 show profilesMySql索引
- MySQL SHOW STATUS命令介紹MySql
- show profiles 詳解
- MySQL pt-show-grants用法介紹MySql
- MySQL高階知識——Show ProfileMySql
- MySQL JDBC 出現多個 SHOW VARIABLES 語句。MySqlJDBC
- MYSQL SHOW VARIABLES簡介MySql
- MySQL調優效能監控之show profileMySql
- MYSQL SHOW PROFILE(剖析報告)的檢視MySql
- MySQL 5.5 LOCK TABLES 和 UNLOCK TABLES 語句介紹MySql
- MySQL 5.5 FLUSH TABLES WITH READ LOCK語句介紹MySql
- mysql show命令MySql
- mysql的show processlistMySql
- mysql show processlist stateMySql
- 慢查詢分析調優工具~show profile
- MySQL 5.7 LIMIT語句介紹MySqlMIT
- MySQL 5.5 mysqlimport介紹MySqlImport
- 【MySQL】SHOW WARNINGS和SHOW ERRORS的作用是什麼?MySqlError
- MySQL 之 show processlist 神器MySql
- Mysql---show table statusMySql
- MySQL中的show命令MySql
- mysql show processlist 詳解MySql
- MySQL 5.5 mysqlbinlog 介紹MySql
- MySQL show status 命令詳解MySql
- MySQL show processlist故障處理MySql
- MySQL的show engine innodb statusMySql
- Mysql show processlist 排查問題MySql
- mysql show命令用法大全MySql
- 轉載:mysql的show processlistMySql
- mysql show processlist命令詳解MySql
- MySQL 5.7 PREPARE、EXECUTE、DEALLOCATE語句介紹MySql
- MySQL使用profile分析語句效能消耗MySql
- MySQL 5.5儲存引擎介紹MySql儲存引擎
- MySQL中show命令用法大全MySql
- MySQL show engine innodb status 詳解MySql
- MySQL Show命令的用法大全MySql
- MySQL 中 show full processlist 詳解MySql