小編給大家分享一下MySQLdumpslow工具怎么用,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
創(chuàng)新互聯(lián)公司專注于企業(yè)營銷型網(wǎng)站、網(wǎng)站重做改版、莒縣網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5場景定制、成都做商城網(wǎng)站、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為莒縣等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
mysqldumpslow工具
開啟慢查詢
查看慢查詢相關(guān)參數(shù)
slow_query_log:慢查詢是否開啟
slow_query_log_file:慢查詢文件位置
long_query_time:超過多長時(shí)間記錄
log_queries_not_using_indexes:沒有使用索引的sql
mysql> show variables like 'slow_query%';
+---------------------+----------------------------+
| Variable_name | Value |
+---------------------+----------------------------+
| slow_query_log | ON |
| slow_query_log_file | /var/lib/mysql/db-slow.log |
+---------------------+----------------------------+
2 rows in set (0.01 sec)
mysql> show variables like 'long_query_time';
+-----------------+----------+
| Variable_name | Value |
+-----------------+----------+
| long_query_time | 2.000000 |
+-----------------+----------+
1 row in set (0.00 sec)
mysql> show variables like 'log_queries_not%';
+-------------------------------+-------+
| Variable_name | Value |
+-------------------------------+-------+
| log_queries_not_using_indexes | OFF |
+-------------------------------+-------+
1 row in set (0.00 sec)
設(shè)置方法
方法1:全局變量設(shè)置
mysql> set global slow_query_log='ON';
mysql> set global slow_query_log_file='/var/lib/mysql/db-slow.log';
mysql> set global long_query_time=2;
mysql> set global log_queries_not_using_indexes=1;
方法2:配置文件設(shè)置
修改配置文件my.cnf在[mysqld]下加入如下內(nèi)容
slow_query_log = ON
slow_query_log_file = /var/lib/mysql/db-slow.log
long_query_time = 2
log_queries_not_using_indexes=1
修改后重啟mysql服務(wù)
測試
mysql> select sleep(3);
[root@db ~]# tail -f /var/lib/mysql/db-slow.log
# Time: 2018-12-25T08:00:48.199670Z
# User@Host: root[root] @ localhost [] Id: 2443797
# Query_time: 3.000198 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
SET timestamp=1545724848;
select sleep(3);
[root@db ~]# 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
常用參數(shù)
-s 排序方式 后面跟排序列
al 平均鎖定時(shí)間
ar 平均返回記錄時(shí)間
at 平均查詢時(shí)間(默認(rèn))
c 計(jì)數(shù)
l 鎖定時(shí)間
r 返回記錄
t 查詢時(shí)間
-r 反向排序,最大的在最后
-t 后面跟數(shù)字,返回行數(shù)
-a 不將所有的數(shù)字抽象為N,字符串抽象為S
-n 后面跟數(shù)字,在名稱中至少有n個(gè)數(shù)字抽象為數(shù)字
-g 正則后邊可以寫一個(gè)正則匹配模式,大小寫不敏感的
案例:
1.根據(jù)計(jì)數(shù)返回5條記錄
mysqldumpslow -s c -t 5 /var/lib/mysql/db-slow.log
2.根據(jù)返回記錄返回5條記錄
mysqldumpslow -s r -t 5 /var/lib/mysql/db-slow.log
3.根據(jù)查詢時(shí)間返回5條記錄
mysqldumpslow -s t -t 5 /var/lib/mysql/db-slow.log
4.根據(jù)計(jì)數(shù)統(tǒng)計(jì),不抽象數(shù)字及字符串
mysqldumpslow -s c -a -t 5 /var/lib/mysql/db-slow.log
看完了這篇文章,相信你對“mysqldumpslow工具怎么用”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!