mysql:log_analyze
ログの解析
全クエリログの取得開始
set global slow_query_log = 1; set global slow_query_log_file = '/var/log/mysql/mysql-slow-all.log'; set global long_query_time = 0;
1秒以上かかっているクエリのみログ出力
set global slow_query_log_file = '/var/log/mysql/mysql-slow.log'; set global long_query_time = 1;
mysqldumpslowで解析
#一番時間がかかっているクエリ mysqldumpslow -s t /var/log/mysql/mysql-slow-all.log #実行回数の多い順 mysqldumpslow -s c /var/log/mysql/mysql-slow-all.log #合計実行時間順に10件表示 mysqldumpslow -s t -t 10 /var/log/mysql/mysql-slow-all.log #平均実行時間順に10件表示 mysqldumpslow -s at -t 10 /var/log/mysql/mysql-slow-all.log #一番時間がかかっているクエリ(リテラル値の表示) mysqldumpslow -a -s t /var/log/mysql/mysql-slow-all.log #SQL文に「test」という文字列が入っているもので、平均実行時間の長い順にTOPから10件(リテラル値の表示) mysqldumpslow -a -s at -t 10 -g test /var/log/mysql/mysql-slow-all.log
オプション
-a リテラル値の表示。この指定が無い場合には、文字列 → S、 数字 → N と置換されて表示される -s ORDER ソート al → 平均ロックタイムの長い順 ar → 平均行数の多い順 at → 平均実行時間の長い順 c → 総クエリ数の多い順 l → 総ロックタイムの長い順 r → 総行数の多い順 t → 総実行時間の長い順 -t NUM 最新の何件を取得するか
ヘルプ
# mysqldumpslow --help
Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]
Parse and summarize the MySQL slow query log. Options are
--verbose verbose
--debug debug
--help write this text to standard output
-v verbose
-d debug
-s ORDER what to sort by (al, at, ar, c, l, r, t), 'at' is default
al: average lock time
ar: average rows sent
at: average query time
c: count
l: lock time
r: rows sent
t: query time
-r reverse the sort order (largest last instead of first)
-t NUM just show the top n queries
-a don't abstract all numbers to N and strings to 'S'
-n NUM abstract numbers with at least n digits within names
-g PATTERN grep: only consider stmts that include this string
-h HOSTNAME hostname of db server for *-slow.log filename (can be wildcard),
default is '*', i.e. match all
-i NAME name of server instance (if using mysql.server startup script)
-l don't subtract lock time from total time
mysql/log_analyze.txt · 最終更新: 2025/02/16 13:53 by 127.0.0.1
