1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
查看慢查詢日誌是否開啓 OFF關閉 ON開啓
show variables like
'slow_query_log'
開啓慢查詢日誌
set global slow_query_log = on
慢查詢日誌所存儲的文件位置
show variables like
'slow_query_log_file'
設置慢查詢日誌位置
set global slow_query_log_file =
'/var/lib/mysql/iZbp1akzlq26t30fbsdwh7Z-slow.log'
是否吧沒有使用索引的sql記錄到慢查詢日誌當中 PFF關閉 ON開啓
show variables like
'log_queries_not_using_indexes'
設置吧沒有使用索引的sql記錄添加到慢查詢日誌當中
set global log_queries_not_using_indexes = on;
查看long_query_time設置的時間
show variables like
'long_query_time'
;
超過多少秒以後的查詢記錄到慢查詢日誌當中
set [session|global] long_query_time =
1
|
2.慢查詢日誌存儲格式html
1
2
3
4
5
6
7
8
9
10
|
-- 執行sql時間
# Time:
2018
-
06
-26T07:
23
:
35
.892991Z
-- 執行SQL的主機信息
# User
@Host
: root[root] @ localhost [] Id:
387088
-- SQL的執行信息
# Query_time:
0.000155
Lock_time:
0.000057
Rows_sent:
12
Rows_examined:
31
-- SQL執行時間
SET timestamp=
1529997815
;
-- SQL內容
SELECT `key`,`value` FROM `yp_setti
|
3.慢查詢日誌的分析工具 mysqldumpslowjava
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
[root
@iZbp1akzlq26t30fbsdwh7Z
mysql] # mysqldumpslow -h
Option h requires an argument
ERROR: bad option
# 最簡單的使用方式 mysqldumpslow 慢查詢日誌目錄
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參數 經過什麼方式來排序
-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 查看前多少條日誌
-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
|
4.mysqldumpslow 分析結果mysql
1
2
3
4
5
6
7
8
9
10
|
[root
@iZbp1akzlq26t30fbsdwh7Z
mysql]# mysqldumpslow /var/lib/mysql/iZbp1akzlq26t30fbsdwh7Z-slow.log -t
2
-s al
Reading mysql slow query log from /var/lib/mysql/iZbp1akzlq26t30fbsdwh7Z-slow.log
-- count 執行次數
-- time 執行時間
-- lock 鎖定時間
-- rows 返回條數
-- root[root]
@localhost
經過那個用戶執行的
Count:
5
Time=
0
.00s (0s) Lock=
0
.01s (0s) Rows=
5.0
(
25
), root[root]
@localhost
SHOW COLUMNS FROM `yp_area`
|