轉 mysql 巡檢腳本


##感謝TSMYK Java技術大雜燴 2019-06-29

 

https://mp.weixin.qq.com/s?__biz=MzU2NjAyNjk2Mw==&mid=2247483912&idx=1&sn=063f744d30d3ed224c6aca825cd1b11d&chksm=fcb3f5b4cbc47ca2a2f772f829f55ce84984af349596cf6743f22811c3db07cebd066c9526cc&mpshare=1&scene=1&srcid=0509lXoPjMLmJ4kJUrhWIcMs&sharer_sharetime=1588993909055&sharer_shareid=5482e59e5224e26ac6c8fa00ebf40ad9&exportkey=Acyhuhx431Ut8T%2BqAZUBUok%3D&pass_ticket=%2Bd9lGyiVOtq4fbLDesHhwF9U8TgRma%2Bjw2pOhoh3p2AgMGTwCW1rVipixHu7%2Fvx3#rd

前言
shell 中執行 mysql 命令
各項巡檢命令
shell 腳本實現

前言

在系統運行的過程中,DBA需要經常的對數據庫進行一些檢查,如數據庫磁盤的占用量,緩存的命中率,內存的分配等;由於有個客戶需要對系統的數據庫進行檢查,所以進行了一些學習,在此記錄下;由於不可能讓用戶手動的輸入這些繁瑣的命令,所以寫了個 shell 腳本。

shell 腳本中連接數據庫執行mysql 命令

在 shell 腳本中,去鏈接數據庫,並執行相關的命令的步驟如下:

  1. 首先使用 touch 命令創建個文件, 使用 chmod 賦給這個文件執行權限

  2. 在文件中輸入如下shell:

#!/bin/bash

host="127.0.0.1" #數據庫IP
port="3306" #數據庫端口
userName="root" #用戶名
password="root" #密碼
dbname="dbname" #數據庫 名稱
dbset="--default-character-set=utf8 -A" # 字符集

cmd="show variables like '%datadir%';"
/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${cmd}")

如果要一次執行多個命令,則直接寫多條命令就可以了,但是記得要換行,如下所示:

cmd2="show variables like '%datadir%';
show tables;
show databases;"
/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${cmd}")

各項巡檢命令

mysql 的數據文件存放的位置

有時候需要知道mysql數據文件的存放位置,此時,可以使用 datadir 變量查看,命令如下:

  1. 進入到MySQL的bin目錄下,執行如下命令來登陸mysql

./mysql -h127.0.0.1 -uroot -proot 

 

  1. 然后執行 show variables like '%datadir%';  或者 elect @@datadir; 命令查看數據文件的存放路徑:

shell腳本如下:

#!/bin/bash

host="127.0.0.1" #數據庫IP
port="3306" #數據庫端口
userName="root" #用戶名
password="root" #密碼
dbname="dbname" #數據庫 名稱
dbset="--default-character-set=utf8 -A" # 字符集

datadir="show variables like '%datadir%';"
datadir_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${datadir}")
echo "mysql 數據文件存放位置:" `echo ${datadir_val} | cut -d' ' -f4`

其中,“cut -d' ' -f4” 意思是獲取到字符串按照空格(‘ ’)進行分割,然后取第 4 個;

查看MySQL中執行次數最多的前 10 條SQL

在MySQL中,要統計執行次數最大的SQL ,需要開啟慢查詢,通過慢查詢日志進行統計,

  1. 查看是否開啟慢查詢日志命令:

show variables like '%slow_query%';

 

其中,slow_query_log 表示是否開啟慢查詢,OFF表示未開啟,ON 表示開啟。slow_query_log_file表示慢查詢日志的路徑。

  1. 開啟慢查詢日志

set global slow_query_log=ON;

慢查詢是指SQL的執行時間超過一定的秒數之后才算是慢查詢,這個時間默認是10秒,可以通過 long_query_time 變量查看,如下:

show variables like '%long_query_time%'; 

 

在測試的時候,可以把這個時間設置短一些,可以設置為1秒,0.1秒或者0.01秒都可以,通過如下命令設置:

set global long_query_time=秒數

 

當設置成功后,再次執行show variables like '%long_query_time%';命令來查看發現還是10秒,這時需要重新退出的,在進行登錄,再查看就好了。

當開啟慢查詢日志后,就可以通過慢查詢日志來分析執行次數最多的SQL了。

使用MySQL提供的 mysqldumpslow 工具來進行分析慢查詢日志。mysqldumpslow 工具的主要功能是統計不同慢SQL的:

    執行次數(count)
    執行最長時間(time)
    等待鎖的時間(lock)
    發送給客戶端的總行數(rows)

進入到mysql的bin目錄下,執行 mysqldumpslow -help 來查看參數,如下:

-s:表示按照哪種方式進行排序,c, t, l, r, 分別表示按照執行次數,執行時間,等待鎖時間和返回的記錄數來排序,at, al, ar 分別按照平均執行時間,平均等待鎖時間和平均發送行數進行排序。
-r:是前面排序的逆序
-t:top n 的意思,即返回排序后前面 n 條的數據
-g:正則匹配

 

現在可以通過該工具來統計執行次數最多的前 10 條SQL了,命令如下:

# -s c -t 10 表示按照執行次數排序,之后,取前10條
./mysqldumpslow -s c -t 10 /home/datas/mysql/data/R6-slow.log;

 

查看數據庫緩存的命中率

首先看下是否開啟了查詢緩存:

show variables like '%query_cache%';

 

其中 query_cache_type為 ON 表示開啟查詢緩存,OFF 表示關閉緩存

query_cache_size 允許設置的值最小為40K,對於最大值則可以幾乎認為無限制,但是,該值並不是越大, 查詢緩存的命中率就越高,需要根據情況來定。

開啟了查詢緩存之后,接下來來看下緩存的相關選項說明:
執行查看命令:

show global status like 'QCache%';

 

  1. Qcache_free_blocks:目前還處於空閑狀態的 Query Cache 中內存 Block 數目

  2. Qcache_free_memory:目前還處於空閑狀態的 Query Cache 內存總量

  3. Qcache_hits:Query Cache 命中次數

  4. Qcache_inserts:向 Query Cache 中插入新的 Query Cache 的次數,也就是沒有命中的次數

  5. Qcache_lowmem_prunes:當 Query Cache 內存容量不夠,需要從中刪除老的 Query Cache 以給新的 Cache 對象使用的次數

  6. Qcache_not_cached:沒有被 Cache 的 SQL 數,包括無法被 Cache 的 SQL 以及由於 query_cache_type 設置的不會被 7. Cache 的 SQL

  7. Qcache_queries_in_cache:目前在 Query Cache 中的 SQL 數量

  8. Qcache_total_blocks:Query Cache 中總的 Block 數量

此時可以根據這些值進行計算緩存的命中率和緩存的內存使用率

公式:

查詢緩存命中率 ≈ (Qcache_hits – Qcache_inserts) / Qcache_hits * 100%
查詢緩存內存使用率 ≈ (query_cache_size – Qcache_free_memory) / query_cache_size * 100%

shell腳本計算緩存命中率:

#!/bin/bash

host="127.0.0.1" #數據庫IP
port="3306" #數據庫端口
userName="root" #用戶名
password="root" #密碼
dbname="dbname" #數據庫 名稱
dbset="--default-character-set=utf8 -A" # 字符集

cache_hits="show global status like 'QCache_hits';"
hits=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${cache_hits}")
hits_val=`echo ${hits} | cut -d' ' -f4`
echo "緩存命中次數:" ${hits_val}

cache_not_hits="show global status like  'Qcache_inserts';"
not_hits=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${cache_not_hits}")
not_hits_val=`echo ${not_hits} | cut -d' ' -f4`
echo "緩存未命中次數:" ${not_hits_val}

cache_hits_rate_1=$(($hits_val - $not_hits_val))
cache_hits_rate_2=`echo | awk "{print $cache_hits_rate_1/$hits_val * 100}"`

echo "緩存命中率:" ${cache_hits_rate_2} "%"

執行該腳本,如下所示:

查詢等待事件的TOP 10

查詢等待事件相關的需要通過 performance_schema 來進行統計,MySQL的 performance schema 主要用於監控MySQL server在一個較低級別的運行過程中的資源消耗、資源等待等.

關於 performance_schema 的介紹,可以參考 https://mp.weixin.qq.com/s?__biz=MzU0MTczNzA1OA==&mid=2247483711&idx=1&sn=aef31942ae6294053cddc0ba83630597&chksm=fb242832cc53a12477febfb309aa5ed9c4c5652a7dafee28ac32ce81a214a0fd72758ff045e9&scene=21#wechat_redirect,介紹得比較詳細。

統計 top 10 的等待事件 SQL 如下:

select event_name, count_star, sum_timer_wait from performance_schema.events_waits_summary_by_user_by_event_name where count_star > order by sum_timer_wait desc limit 10;

 

shell腳本執行

#!/bin/bash

host="127.0.0.1" #數據庫IP
port="3306" #數據庫端口
userName="root" #用戶名
password="root" #密碼
dbname="dbname" #數據庫 名稱
dbset="--default-character-set=utf8 -A" # 字符集

top_event_10="select event_name, count_star, sum_timer_wait from performance_schema.events_waits_summary_global_by_event_name where count_star > 0 order by sum_timer_wait desc limit 10;"
echo "等待事件 TOP 10:"
/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${top_event_10}"

 

 

mysql的內存配置情況,

可以通過查看相關的變量來查看mysql內存 分配:

show variables like 'innodb_buffer_pool_size'; //InnoDB 數據和索引緩存
show variables like 'innodb_log_buffer_size'; // InnoDB 日志緩沖區
show variables like 'binlog_cache_size'; // 二進制日志緩沖區
show variables like 'thread_cache_size'; // 連接線程緩存
show variables like 'query_cache_size'; // 查詢緩存
show variables like 'table_open_cache'; // 表緩存
show variables like 'table_definition_cache'; // 表定義信息緩存
show variables like 'max_connections'; // 最大線程數
show variables like 'thread_stack'; // 線程棧信息使用內存
show variables like 'sort_buffer_size'; // 排序使用內存
show variables like 'join_buffer_size'; // Join操作使用內存
show variables like 'read_buffer_size'; // 順序讀取數據緩沖區使用內存
show variables like 'read_rnd_buffer_size'; // 隨機讀取數據緩沖區使用內存
show variables like 'tmp_table_size'; // 臨時表使用內存

除了使用 show variables 的方式。還可以使用 select @@xxx 的方式:

shell 腳本:

#!/bin/bash

host="127.0.0.1" #數據庫IP
port="3306" #數據庫端口
userName="root" #用戶名
password="root" #密碼
dbname="dbname" #數據庫 名稱
dbset="--default-character-set=utf8 -A" # 字符集

echo "================= 內存配置情況 ==============================="

mem_dis_1="show variables like 'innodb_buffer_pool_size';"
mem_dis_1_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_1}")
mem_dis_1_val_1=`echo ${mem_dis_1_val} | cut -d' ' -f4`
mem_dis_1_val_2=`echo | awk "{print $mem_dis_1_val_1/1024/1024}"`
echo "InnoDB 數據和索引緩存:" $mem_dis_1_val_1

mem_dis_2="show variables like 'innodb_log_buffer_size';"
mem_dis_2_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_2}")
mem_dis_2_val_1=`echo ${mem_dis_2_val} | cut -d' ' -f4`
mem_dis_2_val_2=`echo | awk "{print $mem_dis_2_val_1/1024/1024}"`
echo "InnoDB 日志緩沖區:" $mem_dis_2_val_1

mem_dis_3="show variables like 'binlog_cache_size';"
mem_dis_3_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_3}")
mem_dis_3_val_1=`echo ${mem_dis_3_val} | cut -d' ' -f4`
mem_dis_3_val_2=`echo | awk "{print $mem_dis_3_val_1/1024/1024}"`
echo "二進制日志緩沖區:" $mem_dis_3_val_1

mem_dis_4="show variables like 'thread_cache_size';"
mem_dis_4_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_4}")
echo "連接線程緩存:" `echo $mem_dis_4_val | cut -d' ' -f4`

mem_dis_5="show variables like 'query_cache_size';"
mem_dis_5_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_5}")
echo "查詢緩存:" `echo ${mem_dis_5_val} | cut -d' ' -f4`

mem_dis_6="show variables like 'table_open_cache';"
mem_dis_6_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_6}")
echo "表緩存:" `echo ${mem_dis_6_val} | cut -d' ' -f4`

mem_dis_7="show variables like 'table_definition_cache';"
mem_dis_7_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_7}")
echo "表定義緩存:" `echo ${mem_dis_7_val} | cut -d' ' -f4`

mem_dis_8="show variables like 'max_connections';"
mem_dis_8_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_8}")
echo "最大線程數:" `echo ${mem_dis_8_val} | cut -d' ' -f4`

mem_dis_9="show variables like 'thread_stack';"
mem_dis_9_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_9}")
echo "線程棧信息使用內存:" `echo ${mem_dis_9_val} | cut -d' ' -f4`

mem_dis_10="show variables like 'sort_buffer_size';"
mem_dis_10_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_10}")
echo "排序使用內存:" `echo ${mem_dis_10_val} | cut -d' ' -f4`

mem_dis_11="show variables like 'join_buffer_size';"
mem_dis_11_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_11}")
echo "Join操作使用內存:" `echo ${mem_dis_11_val} | cut -d' ' -f4`

mem_dis_12="show variables like 'read_buffer_size';"
mem_dis_12_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_12}")
echo "順序讀取數據緩沖區使用內存:" `echo ${mem_dis_12_val} | cut -d' ' -f4`

mem_dis_13="show variables like 'read_rnd_buffer_size';"
mem_dis_13_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_13}")
echo "隨機讀取數據緩沖區使用內存:" `echo ${mem_dis_13_val} | cut -d' ' -f4`

mem_dis_14="show variables like 'tmp_table_size';"
mem_dis_14_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${mem_dis_14}")
echo "臨時表使用內存:" `echo ${mem_dis_14_val} | cut -d' ' -f4`

執行😀結果:

查看數據庫的磁盤占用量

1.查詢整個數據庫的占用量

select sum((data_length+index_length)/1024/1024) m from information_schema.tables where table_schema="dbname";

2.某個表的占用量:

select (data_length+index_length)/1024/1024 M from information_schema.tables where table_schema="dbname" and table_name="table_name";

3.整個mysql server 所有數據庫的磁盤用量

select table_schema, sum((data_length+index_length)/1024/1024) M from information_schema.tables where table_schema is not null group by table_schema;

shell 腳本:

host="127.0.0.1"
port="3306"
userName="root"
password="root"
dbname="dbname"
dbset="--default-character-set=utf8 -A"

echo "================= 數據庫磁盤占用量 ==========================="

_disk_used="select sum((data_length+index_length)/1024/1024) M from information_schema.tables where table_schema=\"m_dp_eup\""

_disk_used_val=$(/home/mysql/bin/mysql -h${host} -u${userName} -p${password} ${dbname} -P${port} -e "${_disk_used}")
echo "磁盤占用量(單位:M):" `echo ${_disk_used_val} | cut -d' ' -f2`

 

分析 mysql 的錯誤日志

當系統在運行中,mysql 可以會有一些異常,可以通過查看錯誤日志來分析。

查看mysql的錯誤日志文件:

show global variables like 'log_error'; 
#或 
select @@log_error;

使用 grep 命令查找錯誤信息輸出到文件:

grep 'error' ./mysql.err* > error.log 或 egrep -i 'error|Failed' ./mysqld.err* > error.log

如下想根據時間來過濾,則可以在后面加上日期就可以了

grep -i -E 'error' ./mysqld.err* | grep -E '2019-03-28|2019-06-14' > error.log

 

shell 腳本:

查看最近一周的錯誤日志文件中是否有錯誤

_time=$(date -d '6 days ago' +%Y-%m-%d)\|$(date -d '5 days ago' +%Y-%m-%d)\|$(date -d '4 days ago' +%Y-%m-%d)\|$(date -d '3 days ago' +%Y-%m-%d)\|$(date -d '2 days ago' +%Y-%m-%d)\|$(date -d '1 days ago' +%Y-%m-%d)\|$(date -d '0 days ago' +%Y-%m-%d)

echo "==================最近一周的錯誤日志 =========================="

#grep -i -E 'error' /home/logs/mysql/mysqld.err* | grep -E '2019-03-28|2019-06-14'
grep -i -E 'error' /home/logs/mysql/mysql.err*| grep -E \'$_time\'

_time 是獲取最近一周的日期,形如:'2019-06-13|2019-06-14|………………………'

當然還有很多的檢查項,這里就不一一列出來了。

以上就是一些檢查項及其 shell 腳本的實現

 

###如果是5.6 以及56.以下版本的mysql , 最好能建立sys database;

 

https://github.com/mysql/mysql-sys

感謝MarkLeith 

 

 

安裝方法如下:

The MySQL sys schema

A collection of views, functions and procedures to help MySQL administrators get insight in to MySQL Database usage.

There are install files available for 5.6 and 5.7 respectively. To load these, you must position yourself within the directory that you downloaded to, as these top level files SOURCE individual files that are shared across versions in most cases (though not all).

Installation

The objects should all be created as the root user (but run with the privileges of the invoker).

For instance if you download to /tmp/mysql-sys/, and want to install the 5.6 version you should:

cd /tmp/mysql-sys/
mysql -u root -p < ./sys_56.sql

Or if you would like to log in to the client, and install the 5.7 version:

cd /tmp/mysql-sys/
mysql -u root -p 
SOURCE ./sys_57.sql

Alternatively, you could just choose to load individual files based on your needs, but beware, certain objects have dependencies on other objects. You will need to ensure that these are also loaded.

 

###########sample

4.1巡檢報告里有一個項目

4.2   I/O寫最多的5個文件  原數據來自  x$io_global_by_file_by_bytes

26.4.3.11 The io_global_by_file_by_bytes and x$io_global_by_file_by_bytes Views

These views summarize global I/O consumers to display amount of I/O, grouped by file. By default, rows are sorted by descending total I/O (bytes read and written).

The io_global_by_file_by_bytes and x$io_global_by_file_by_bytes views have these columns:

file

The file path name.

count_read

The total number of read events for the file.

total_read

The total number of bytes read from the file.

avg_read

The average number of bytes per read from the file.

count_write

The total number of write events for the file.

total_written

The total number of bytes written to the file.

avg_write

The average number of bytes per write to the file.

total

The total number of bytes read and written for the file.

write_pct

The percentage of total bytes of I/O that were writes.

 

4.3 實例輸出如下:

file count_read total_read avg_read count_write total_written avg_write total write_pct
/db/mysql/data/mydata/ibdata1 7872 131039232 16646.2439 2120577 62741856256 29587.1625 62872895488 99.79
/db/mysql/data/mydata/scheduled/triggers.ibd 185 3031040 16384.0000 193640 4465164288 23059.1008 4468195328 99.93

 

解釋如下: /db/mysql/data/mydata/ibdata1 文件  total_written  is 62741856256 bytes. 並且 avg_write is 29587.1625 bytes

.ibd 文件解釋參考https://www.cnblogs.com/feiyun8616/p/12893443.html

 

 

##### sample 3.4 TOP SQL 采集自  x$statement_analysis

 

db exec_count query full_scan avg_latency
NULL 639206 SET `autocommit` = ?   89.64 us
NULL 637710 SET NAMES `utf8`   103.61 us
lepus 469714 SELECT `first_seen` , `last_se ... ry_review` WHERE CHECKSUM = ?  * 286.88 us
lepus 469714 INSERT INTO `lepus` . `mysql_s ... COALESCE ( ? , NOW ( ) ) ) )   5.62 ms

 

解釋如下: 

該段是根據 exec_count 進行排序的,full_scan 這一列是 是否使用全表掃描,avg_latency 是平均每次的執行的等待時間。

 

具體時間解釋如下:

us是微西門子,ms是毫西門子,都是電導的單e68a84e799bee5baa6e997aee7ad9431333366303838位。

S是電導率的單位“西門子”,m(毫)、u(實際是μ,希臘字母“繆”,表示“微”,10的-6次方)是數量級詞頭。

1s=1000ms

1ms=1000us

1us=1000ns

 

26.4.3.35 The statement_analysis and x$statement_analysis Views
These views list normalized statements with aggregated statistics. The content mimics the MySQL Enterprise Monitor Query Analysis view. By default, rows are sorted by descending total latency.

The statement_analysis and x$statement_analysis views have these columns:

query

The normalized statement string.

db

The default database for the statement, or NULL if there is none.

full_scan

The total number of full table scans performed by occurrences of the statement.

exec_count

The total number of times the statement has executed.

err_count

The total number of errors produced by occurrences of the statement.

warn_count

The total number of warnings produced by occurrences of the statement.

total_latency

The total wait time of timed occurrences of the statement.

max_latency

The maximum single wait time of timed occurrences of the statement.

avg_latency

The average wait time per timed occurrence of the statement.

lock_latency

The total time waiting for locks by timed occurrences of the statement.

rows_sent

The total number of rows returned by occurrences of the statement.

rows_sent_avg

The average number of rows returned per occurrence of the statement.

rows_examined

The total number of rows read from storage engines by occurrences of the statement.

rows_examined_avg

The average number of rows read from storage engines per occurrence of the statement.

rows_affected

The total number of rows affected by occurrences of the statement.

rows_affected_avg

The average number of rows affected per occurrence of the statement.

tmp_tables

The total number of internal in-memory temporary tables created by occurrences of the statement.

tmp_disk_tables

The total number of internal on-disk temporary tables created by occurrences of the statement.

rows_sorted

The total number of rows sorted by occurrences of the statement.

sort_merge_passes

The total number of sort merge passes by occurrences of the statement.

digest

The statement digest.

first_seen

The time at which the statement was first seen.

last_seen

The time at which the statement was most recently seen.

 

 

####sample

還有一段來自performance_schema.events_waits_summary_global_by_event_name 

 

3.4.1 TOP WAIT EVENT

event_name count_star sum_timer_wait
idle 23106328 2135447869942725760
wait/io/table/sql/handler 94658377684 987399391349498508

 

sql/handle 這個等待事件,總等待次數為 94658377684次,總等待事件為987399391349498508 皮秒(約為987399 秒)

273238183964000皮秒(1000000000000皮秒=1秒) 12個0

select event_name, count_star, sum_timer_wait from performance_schema.events_waits_summary_global_by_event_name

 

events_waits_summary_global_by_event_name has an EVENT_NAME column. Each row summarizes events for a given event name. An instrument might be used to create multiple instances of the instrumented object. For example, if there is an instrument for a mutex that is created for each connection, there are as many instances as there are connections. The summary row for the instrument summarizes over all these instances.

Each wait event summary table has these summary columns containing aggregated values:

COUNT_STAR

The number of summarized events. This value includes all events, whether timed or nontimed.

SUM_TIMER_WAIT

The total wait time of the summarized timed events. This value is calculated only for timed events because nontimed events have a wait time of NULL. The same is true for the other xxx_TIMER_WAIT values.

MIN_TIMER_WAIT

The minimum wait time of the summarized timed events.

AVG_TIMER_WAIT 皮秒為單位(1000000000000皮秒=1秒)

The average wait time of the summarized timed events.

MAX_TIMER_WAIT

The maximum wait time of the summarized timed events.


感謝 zhoujinyi/

zjy@performance_schema 11:36:28>SELECT SCHEMA_NAME,DIGEST_TEXT,COUNT_STAR,AVG_TIMER_WAIT,SUM_ROWS_SENT,SUM_ROWS_EXAMINED,FIRST_SEEN,LAST_SEEN FROM events_statements_summary_by_digest ORDER BY AVG_TIMER_WAIT desc LIMIT 1\G
*************************** 1. row ***************************
SCHEMA_NAME: dchat
DIGEST_TEXT: SELECT ...
COUNT_STAR: 1
AVG_TIMER_WAIT: 273238183964000
SUM_ROWS_SENT: 50208
SUM_ROWS_EXAMINED: 5565651
FIRST_SEEN: 2016-02-22 13:27:33
LAST_SEEN: 2016-02-22 13:27:33
復制代碼


https://www.cnblogs.com/zhoujinyi/p/5236705.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM