profile怎么在mysql中使用-創(chuàng)新互聯(lián)

這篇文章給大家介紹profile怎么在mysql中使用,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

創(chuàng)新互聯(lián)的客戶來自各行各業(yè),為了共同目標(biāo),我們?cè)诠ぷ魃厦芮信浜?,從?chuàng)業(yè)型小企業(yè)到企事業(yè)單位,感謝他們對(duì)我們的要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來驚喜。專業(yè)領(lǐng)域包括網(wǎng)站建設(shè)、做網(wǎng)站、電商網(wǎng)站開發(fā)、微信營(yíng)銷、系統(tǒng)平臺(tái)開發(fā)。

profile是什么

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

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

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

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

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

對(duì)定位一條語句的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.

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

注意:show profile和show Profiles都是不建議使用的,在mysql后期的版本中可能會(huì)被刪除;官網(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)對(duì)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 對(duì)每個(gè)會(huì)話有效,當(dāng)會(huì)話結(jié)束后,當(dāng)前的profiling信息就會(huì)丟失。

使用案例

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 |
+----------------------+----------+

關(guān)于profile怎么在mysql中使用就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

分享題目:profile怎么在mysql中使用-創(chuàng)新互聯(lián)
網(wǎng)址分享:http://muchs.cn/article0/dpdooo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)、ChatGPT、微信公眾號(hào)、定制開發(fā)網(wǎng)站建設(shè)、網(wǎng)站策劃

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)