MySQL中profiling的使用

MySQL5.0之後便開始支持profiling,用於診斷一條sql在執行過程中的資源消耗情況,可以通過profiling來查看慢sql到底慢在哪裏,從而進行合理的優化

  1. 查看profiling是否支持和開啓
show variables like '%profil%'
Variable_name Value
have_profiling(是否支持profiling) YES
profiling(是否開啓profiling) ON
profiling_history_size(profiling每次展示的行數) 15
  1. 如果上面profiling的值爲0或者OFF,那麼開啓profile
set profiling=1
  1. 開始使用profiling
# 執行一條sql
select count(*) from vc
# 使用profiling
SHOW PROFILES

SHOW PROFILES的執行結果
Query_ID:查詢的ID
Duration:執行的耗時
Query:執行的具體sql
可以在結果中找到我們剛纔執行的那條sql

# 通過Query_ID查看sql具體的執行情況
# 也可以通過Show profile all for query 174查詢更多的信息
Show profile for query 174

在這裏插入圖片描述

Status:表示執行這條sql所經歷的階段
Duration:每個階段的耗時

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章