查看SQL語句執行時間

本文介紹用show profiles 之類的語句來簡單查看sql的執行:

1,查一下profile是否已經打開,默認是不打開的。

mysql> show profiles;

Empty set (0.02 sec)

mysql> show variables like "%pro%";

+---------------------------+-------+

| Variable_name | Value |

+---------------------------+-------+

| profiling | OFF |

| profiling_history_size | 15 |

| protocol_version | 10 |

| slave_compressed_protocol | OFF |

+---------------------------+-------+

4 rows in set (0.00 sec)

2,開啟profile,然后測試

開啟profile

mysql> set profiling=1;

Query OK, 0 rows affected (0.00 sec)

測試如下:

mysql> show tables;

+----------------+

| Tables_in_test |

+----------------+

| aa |

| bb |

| comment |

| string_test |

| user |

+----------------+

5 rows in set (0.00 sec)

mysql> select * from aa;

+----+------+------------+------+

| id | name | nname | sex |

+----+------+------------+------+

| 2 | tank | bbbb,4bbbb | NULL |

| 3 | zhang| 3,c,u | NULL |

+----+------+------------+------+

2 rows in set (0.00 sec)

mysql> update aa set name='d';

Query OK, 2 rows affected (0.00 sec)

Rows matched: 2 Changed: 2 Warnings: 0

mysql> delete from bb;

Query OK, 2 rows affected (0.00 sec)

mysql> show profiles;

+----------+------------+------------------------+

| Query_ID | Duration | Query |

+----------+------------+------------------------+

| 1 | 0.00054775 | show tables |

| 2 | 0.00022400 | select * from aa |

| 3 | 0.00026275 | update aa set name='d' |

| 4 | 0.00043000 | delete from bb |

+----------+------------+------------------------+

4 rows in set (0.00 sec)

mysql> show profile;

+----------------------+-----------+

| Status | Duration |

+----------------------+-----------+

| (initialization) | 0.0000247 |

| checking permissions | 0.0000077 |

| Opening tables | 0.0000099 |

| System lock | 0.000004 |

| Table lock | 0.000005 |

| init | 0.0003057 |

| query end | 0.0000062 |

| freeing items | 0.000057 |

| closing tables | 0.000008 |

| logging slow query | 0.0000015 |

+----------------------+-----------+

10 rows in set (0.00 sec)

mysql> show profile for query 1;

+----------------------+-----------+

| Status | Duration |

+----------------------+-----------+

| (initialization) | 0.000028 |

| checking permissions | 0.000007 |

| Opening tables | 0.0000939 |

| System lock | 0.0000017 |

| Table lock | 0.0000055 |

| init | 0.000009 |

| optimizing | 0.0000027 |

| statistics | 0.0000085 |

| preparing | 0.0000065 |

| executing | 0.000004 |

| checking permissions | 0.000258 |

| Sending data | 0.000049 |

| end | 0.0000037 |

| query end | 0.0000027 |

| freeing items | 0.0000307 |

| closing tables | 0.0000032 |

| removing tmp table | 0.0000275 |

| closing tables | 0.0000037 |

| logging slow query | 0.000002 |

+----------------------+-----------+

19 rows in set (0.00 sec)

mysql> show profile for query 3;

+----------------------+-----------+

| Status | Duration |

+----------------------+-----------+

| (initialization) | 0.0000475 |

| checking permissions | 0.0000077 |

| Opening tables | 0.000026 |

| System lock | 0.0000042 |

| Table lock | 0.0000045 |

| init | 0.0000205 |

| Updating | 0.0000787 |

| end | 0.0000567 |

| query end | 0.000004 |

| freeing items | 0.0000067 |

| closing tables | 0.000004 |

| logging slow query | 0.000002 |

+----------------------+-----------+

12 rows in set (0.00 sec)

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 分析SQL執行帶來的開銷是優化SQL的重要手段。在MySQL數據庫中,可以通過配置profiling參數來啟用SQ...
    張偉科閱讀 1,112評論 0 1
  • 【MySQL】Linux下MySQL 5.5、5.6和5.7的RPM、二進制和源碼安裝 1.1BLOG文檔結構圖 ...
    小麥苗DB寶閱讀 10,601評論 0 31
  • 什么是數據庫? 數據庫是存儲數據的集合的單獨的應用程序。每個數據庫具有一個或多個不同的API,用于創建,訪問,管理...
    chen_000閱讀 4,055評論 0 19
  • 都說做爸爸的,希望自己有一個可愛的女兒,我就是這樣一個幸運的爸爸... 在老婆懷孕的日子里,我有些期待、有些不安、...
    友思享閱讀 306評論 0 2
  • 讀旅行吟5 如夢令·榕城親人晏 (李印中) 泉州福州仙游, 三坊七巷看樓。 榕城親人晏, 舉杯痛飲鄉愁。 喝酒,喝...
    明燭高照閱讀 111評論 0 1