欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

mysql 顯示SQL語句執(zhí)行時(shí)間的代碼

 更新時(shí)間:2009年08月07日 00:22:12   作者:  
查看 MySQL 語法 詳細(xì)執(zhí)行時(shí)間 與 CPU/記憶體使用量: MySQL Query Profiler

MySQL 的 SQL 語法調(diào)整主要都是使用 EXPLAIN , 但是這個(gè)並沒辦法知道詳細(xì)的 Ram(Memory)/CPU 等使用量.

於 MySQL 5.0.37 以上開始支援 MySQL Query Profiler, 可以查詢到此 SQL 會(huì)執(zhí)行多少時(shí)間, 並看出 CPU/Memory 使用量, 執(zhí)行過程中 System lock, Table lock 花多少時(shí)間等等.

MySQL Query Profile 詳細(xì)介紹可見: Using the New MySQL Query Profiler (2007.04.05 發(fā)表)

效能分析主要分下述三種(轉(zhuǎn)載自上篇):

Bottleneck analysis - focuses on answering the questions: What is my database server waiting on; what is a user connection waiting on; what is a piece of SQL code waiting on?
Workload analysis - examines the server and who is logged on to determine the resource usage and activity of each.
Ratio-based analysis - utilizes a number of rule-of-thumb ratios to gauge performance of a database, user connection, or piece of code.
MySQL Query Profile 使用方法
啟動(dòng)
mysql> set profiling=1; # 此命令於 MySQL 會(huì)於 information_schema 的 database 建立一個(gè) PROFILING 的 table 來紀(jì)錄.
SQL profiles show
mysql> show profiles; # 從啟動(dòng)之後所有語法及使用時(shí)間, 含錯(cuò)誤語法都會(huì)紀(jì)錄.
ex: (root@localhost) [test]> show profiles; # 注意 Query_ID, 下面執(zhí)行時(shí)間統(tǒng)計(jì)等, 都是依 Query_ID 在紀(jì)錄

 +----------+------------+---------------------------+
 | Query_ID | Duration   | Query                     |
 +----------+------------+---------------------------+
 |        1 | 0.00090400 | show profile for query 1  |
 |        2 | 0.00008700 | select * from users       |
 |        3 | 0.00183800 | show tables               |
 |        4 | 0.00027600 | mysql> show profiles      |
 +----------+------------+---------------------------+
 查詢所有花費(fèi)時(shí)間加總
mysql> select sum(duration) from information_schema.profiling where query_id=1; # Query ID = 1

 +---------------+
 | sum(duration) |
 +---------------+
 |      0.000447 |
 +---------------+
 查詢各執(zhí)行階段花費(fèi)多少時(shí)間
mysql> show profile for query 1; # Query ID = 1

 +--------------------+------------+
 | Status             | Duration   |
 +--------------------+------------+
 | (initialization)   | 0.00006300 |
 | Opening tables     | 0.00001400 |
 | System lock        | 0.00000600 |
 | Table lock         | 0.00001000 |
 | init               | 0.00002200 |
 | optimizing         | 0.00001100 |
 | statistics         | 0.00009300 |
 | preparing          | 0.00001700 |
 | executing          | 0.00000700 |
 | Sending data       | 0.00016800 |
 | end                | 0.00000700 |
 | query end          | 0.00000500 |
 | freeing items      | 0.00001200 |
 | closing tables     | 0.00000800 |
 | logging slow query | 0.00000400 |
 +--------------------+------------+
 查詢各執(zhí)行階段花費(fèi)的各種資源列表
mysql> show profile cpu for query 1; # Query ID = 1

 +--------------------------------+----------+----------+------------+
 | Status                         | Duration | CPU_user | CPU_system |
 +--------------------------------+----------+----------+------------+
 | (initialization)               | 0.000007 | 0        | 0          |
 | checking query cache for query | 0.000071 | 0        | 0          |
 | Opening tables                 | 0.000024 | 0        | 0          |
 | System lock                    | 0.000014 | 0        | 0          |
 | Table lock                     | 0.000055 | 0.001    | 0          |
 | init                           | 0.000036 | 0        | 0          |
 | optimizing                     | 0.000013 | 0        | 0          |
 | statistics                     | 0.000021 | 0        | 0          |
 | preparing                      | 0.00002  | 0        | 0          |
 | executing                      | 0.00001  | 0        | 0          |
 | Sending data                   | 0.015072 | 0.011998 | 0          |
 | end                            | 0.000021 | 0        | 0          |
 | query end                      | 0.000011 | 0        | 0          |
 | storing result in query cache  | 0.00001  | 0        | 0          |
 | freeing items                  | 0.000018 | 0        | 0          |
 | closing tables                 | 0.000019 | 0        | 0          |
 | logging slow query             | 0.000009 | 0        | 0          |
 +--------------------------------+----------+----------+------------+
 mysql> show profile IPC for query 1;

 +--------------------------------+----------+---------------+-------------------+
 | Status                         | Duration | Messages_sent | Messages_received |
 +--------------------------------+----------+---------------+-------------------+
 | (initialization)               | 0.000007 |             0 |                 0 |
 | checking query cache for query | 0.000071 |             0 |                 0 |
 | Opening tables                 | 0.000024 |             0 |                 0 |
 | System lock                    | 0.000014 |             0 |                 0 |
 | Table lock                     | 0.000055 |             0 |                 0 |
 | init                           | 0.000036 |             0 |                 0 |
 | optimizing                     | 0.000013 |             0 |                 0 |
 | statistics                     | 0.000021 |             0 |                 0 |
 | preparing                      | 0.00002  |             0 |                 0 |
 | executing                      | 0.00001  |             0 |                 0 |
 | Sending data                   | 0.015072 |             0 |                 0 |
 | end                            | 0.000021 |             0 |                 0 |
 | query end                      | 0.000011 |             0 |                 0 |
 | storing result in query cache  | 0.00001  |             0 |                 0 |
 | freeing items                  | 0.000018 |             0 |                 0 |
 | closing tables                 | 0.000019 |             0 |                 0 |
 | logging slow query             | 0.000009 |             0 |                 0 |
 +--------------------------------+----------+---------------+-------------------+
 其它屬性列表
ALL - displays all information
BLOCK IO - displays counts for block input and output operations
CONTEXT SWITCHES - displays counts for voluntary and involuntary context switches
IPC - displays counts for messages sent and received
MEMORY - is not currently implemented
PAGE FAULTS - displays counts for major and minor page faults
SOURCE - displays the names of functions from the source code, together with the name and line number of the file in which the function occurs
SWAPS - displays swap counts
設(shè)定 Profiling 存的 Size
mysql> show variables where variable_name='profiling_history_size'; # 預(yù)設(shè)是 15筆
關(guān)閉
mysql> set profiling=0;

相關(guān)文章

  • MySQL 替換某字段內(nèi)部分內(nèi)容的UPDATE語句

    MySQL 替換某字段內(nèi)部分內(nèi)容的UPDATE語句

    至于字段內(nèi)部分內(nèi)容:比如替換標(biāo)題里面的產(chǎn)品價(jià)格,接下來為你詳細(xì)介紹下UPDATE語句的寫法,感興趣的你可以參考下哈,希望可以幫助到你
    2013-03-03
  • Navicat Premium遠(yuǎn)程連接MySQL數(shù)據(jù)庫(kù)的方法

    Navicat Premium遠(yuǎn)程連接MySQL數(shù)據(jù)庫(kù)的方法

    這篇文章主要介紹了Navicat Premium遠(yuǎn)程連接MySQL數(shù)據(jù)庫(kù)的方法,本文分步驟通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-12-12
  • MySQL視圖的概念、創(chuàng)建、查看、刪除和修改詳解

    MySQL視圖的概念、創(chuàng)建、查看、刪除和修改詳解

    視圖是指計(jì)算機(jī)數(shù)據(jù)庫(kù)中的視圖,是一個(gè)虛擬表,其內(nèi)容由查詢定義,下面這篇文章主要給大家介紹了關(guān)于MySQL視圖的概念、創(chuàng)建、查看、刪除和修改的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-08-08
  • php下巧用select語句實(shí)現(xiàn)mysql分頁查詢

    php下巧用select語句實(shí)現(xiàn)mysql分頁查詢

    mysql分頁查詢是我們經(jīng)常見到的問題,那么應(yīng)該如何實(shí)現(xiàn)呢?下面就教您一個(gè)實(shí)現(xiàn)mysql分頁查詢的好方法,供您參考學(xué)習(xí)。
    2010-12-12
  • MySQL Innodb 存儲(chǔ)結(jié)構(gòu) 和 存儲(chǔ)Null值 用法詳解

    MySQL Innodb 存儲(chǔ)結(jié)構(gòu) 和 存儲(chǔ)Null值 用法詳解

    這篇文章主要介紹了MySQL Innodb 存儲(chǔ)結(jié)構(gòu) 和 存儲(chǔ)Null值 用法詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • MySQL性能優(yōu)化之max_connections配置參數(shù)淺析

    MySQL性能優(yōu)化之max_connections配置參數(shù)淺析

    這篇文章主要介紹了MySQL性能優(yōu)化之max_connections配置參數(shù)淺析,本文著重講解了3種配置max_connections參數(shù)的方法,需要的朋友可以參考下
    2014-07-07
  • mysql 設(shè)置默認(rèn)的時(shí)間值

    mysql 設(shè)置默認(rèn)的時(shí)間值

    由于MySQL目前字段的默認(rèn)值不支持函數(shù)
    2009-05-05
  • 徹底解決MySQL使用中文亂碼的方法

    徹底解決MySQL使用中文亂碼的方法

    本文詳細(xì)講解了徹底解決MySQL使用中文亂碼的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-01-01
  • C# Mysql 查詢 Rownum的解決方法

    C# Mysql 查詢 Rownum的解決方法

    C# Mysql 查詢 Rownum的解決方法,需要的朋友可以參考一下
    2013-03-03
  • MySQL PHP語法淺析

    MySQL PHP語法淺析

    在本篇文章里小編給大家分享了關(guān)于MySQL PHP語法的相關(guān)知識(shí)點(diǎn),需要的朋友們學(xué)習(xí)參考下。
    2019-02-02

最新評(píng)論