婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > mysql中profile的使用方法教程

mysql中profile的使用方法教程

熱門標(biāo)簽:高德地圖標(biāo)注中心個(gè)人注冊 寶應(yīng)電信400電話辦理費(fèi)用 外呼系統(tǒng)服務(wù) 如何在高德地圖標(biāo)注新地址 400電話辦理都選易號網(wǎng) 外呼系統(tǒng)防封號違法嗎 電銷機(jī)器人針對的 湘潭電銷機(jī)器人咨詢電話 高德地圖標(biāo)注模式

profile是什么

當(dāng)我們要對某一條sql的性能進(jìn)行分析時(shí),可以使用它。

Profiling是從 mysql5.0.3版本以后才開放的。

啟動profile之后,所有查詢包括錯(cuò)誤的語句都會記錄在內(nèi)。

關(guān)閉會話或者set profiling=0 就關(guān)閉了。(如果將profiling_history_size參數(shù)設(shè)置為0,同樣具有關(guān)閉MySQL的profiling效果。)

此工具可用來查詢SQL執(zhí)行狀態(tài),System lock和Table lock 花多少時(shí)間等等,

對定位一條語句的I/O消耗和CPU消耗 非常重要。(SQL 語句執(zhí)行所消耗的最大兩部分資源就是IO和CPU)

--在mysql5.7之后,profile信息將逐漸被廢棄,mysql推薦使用performance schema

mysql官網(wǎng)定義

The SHOW PROFILE and SHOW PROFILES statements display profiling information that indicates resource usage for statements executed during the course of the current session.

簡單的說,當(dāng)前會話資源的消耗情況。

注意:show profile和show Profiles都是不建議使用的,在mysql后期的版本中可能會被刪除;官網(wǎng)建議使用Performance Schema

怎么使用

profile默認(rèn)關(guān)閉,生產(chǎn)環(huán)境中也建議關(guān)閉。

查看當(dāng)前環(huán)境的profile設(shè)置

mysql> show variables like '%profiling%';
+------------------------+-------+
| Variable_name   | Value |
+------------------------+-------+
| have_profiling   | YES |
| profiling    | OFF |
| profiling_history_size | 15 |
+------------------------+-------+

profiling off表示profile關(guān)閉,profiling_history_size 15表示保存最近15條SQL的資源消耗情況。

開啟profile功能,可以使用命令

set global profiling = 1;

然后就可以使用下面命令

show profiles;

查看最近15條SQL的情況;

如果要查看某一條的具體情況,SQL格式為:

SHOW PROFILE [type [, type] ... ]
 [FOR QUERY n]
 [LIMIT row_count [OFFSET offset]]

type: {
 ALL
 | BLOCK IO
 | CONTEXT SWITCHES
 | CPU
 | IPC
 | MEMORY
 | PAGE FAULTS
 | SOURCE
 | SWAPS
}

官網(wǎng)對type中各個(gè)字段的解釋為:

    ALL displays all information

    BLOCK IO displays counts for block input and output operations

    CONTEXT SWITCHES displays counts for voluntary and involuntary context switches

    CPU displays user and system CPU usage times

    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

profiling 對每個(gè)會話有效,當(dāng)會話結(jié)束后,當(dāng)前的profiling信息就會丟失。

使用案例

mysql> show profiles;
+----------+------------+----------------------------+
| Query_ID | Duration | Query      |
+----------+------------+----------------------------+
|  1 | 0.00060275 | select * from customers |
|  2 | 0.00222450 | show tables    |
|  3 | 0.00567425 | select * from offices  |
|  4 | 0.00052050 | show tables    |
|  5 | 0.01123300 | select * from payments  |
|  6 | 0.00111675 | show tables    |
|  7 | 0.02049625 | select * from productlines |
+----------+------------+----------------------------+

在排查SQL執(zhí)行情況,或者是哪條SQL執(zhí)行非常慢,慢在哪里;profile都是非常的輔助工具。

顯示一條SQL的具體花銷在哪里

mysql> show profile for query 7;
+----------------------+----------+
| Status    | Duration |
+----------------------+----------+
| starting    | 0.000043 |
| checking permissions | 0.000005 |
| Opening tables  | 0.014552 |
| init     | 0.000025 |
| System lock   | 0.000009 |
| optimizing   | 0.000004 |
| statistics   | 0.000011 |
| preparing   | 0.000010 |
| executing   | 0.000003 |
| Sending data   | 0.005653 |
| end     | 0.000010 |
| query end   | 0.000009 |
| closing tables  | 0.000020 |
| freeing items  | 0.000121 |
| cleaning up   | 0.000023 |
+----------------------+----------+

信息一目了然,這樣我就能對SQL執(zhí)行情況有個(gè)大概的了解。

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

您可能感興趣的文章:
  • MySQL性能分析工具profile使用教程
  • MySQL中使用SHOW PROFILE命令分析性能的用法整理
  • MySQL使用profile查詢性能的操作教程
  • MySQL利用profile分析慢sql詳解(group left join效率高于子查詢)

標(biāo)簽:蘭州 佛山 馬鞍山 南充 黃山 賀州 黔南 宿遷

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《mysql中profile的使用方法教程》,本文關(guān)鍵詞  mysql,中,profile,的,使用方法,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《mysql中profile的使用方法教程》相關(guān)的同類信息!
  • 本頁收集關(guān)于mysql中profile的使用方法教程的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 申扎县| 托里县| 咸阳市| 绥中县| 偏关县| 马边| 毕节市| 沅江市| 女性| 信丰县| 开原市| 永川市| 昌乐县| 雅安市| 屏山县| 灵丘县| 隆化县| 南华县| 小金县| 富裕县| 五大连池市| 原阳县| 社旗县| 康保县| 青川县| 北票市| 襄城县| 鱼台县| 昌图县| 开远市| 高台县| 都昌县| 靖州| 克拉玛依市| 长治县| 宣武区| 周口市| 深泽县| 彭山县| 夏河县| 调兵山市|