您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)MySQL 5.5中SHOW PROFILE、SHOW PROFILES語(yǔ)句怎么用,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
SHOW PROFILE 和 SHOW PROFILES 語(yǔ)句顯示 MySQL 數(shù)據(jù)庫(kù)語(yǔ)句的資源消耗情況。
需要注意的是:這兩條命令均顯示當(dāng)前會(huì)話的SQL資源消耗情況,不能顯示其他會(huì)話的資源消耗情況。
--需要打開(kāi)Profiling參數(shù)
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顯示最近發(fā)送到MySQL服務(wù)器的語(yǔ)句。顯示語(yǔ)句的條數(shù)由profiling_history_size參數(shù)設(shè)定,默認(rèn)值是15,最大值是100,將參數(shù)的值設(shè)為0并不會(huì)關(guān)閉profiling功能。除了SHOW PROFILE 和 SHOW PROFILES,其他的語(yǔ)句都會(huì)顯示在列表中。
SHOW PROFIL會(huì)顯示一條語(yǔ)句的具體信息。如果沒(méi)有指定FOR QUERY語(yǔ)句,輸出結(jié)果會(huì)顯示最后執(zhí)行的語(yǔ)句。如果指定了FOR QUERY和語(yǔ)句編號(hào),則會(huì)顯示指定語(yǔ)句的信息。語(yǔ)句編號(hào)對(duì)應(yīng)SHOW PROFILES顯示結(jié)果中的Query_ID字段。LIMIT語(yǔ)句會(huì)限制輸出的行數(shù)。默認(rèn),SHOW PROFILE語(yǔ)句只顯示狀態(tài)和運(yùn)行時(shí)間這兩個(gè)字段,狀態(tài)字段和SHOW PROCESSLIST里面的狀態(tài)字段相似。
--示例
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解析執(zhí)行過(guò)程中每個(gè)步驟對(duì)應(yīng)的源碼的文件、函數(shù)名以及具體的源文件行數(shù)
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
關(guān)于“MySQL 5.5中SHOW PROFILE、SHOW PROFILES語(yǔ)句怎么用”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。