mysqlsla的安裝與使用

來源:互聯網
上載者:User

author:skate
time:2012/02/17

mysqlsla的安裝與使用

1.下載 mysqlsla
[root@localhost tmp]# wget http://hackmysql.com/scripts/mysqlsla-2.03.tar.gz
--19:45:45--  http://hackmysql.com/scripts/mysqlsla-2.03.tar.gz
Resolving hackmysql.com... 64.13.232.157
Connecting to hackmysql.com|64.13.232.157|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 33674 (33K) [application/x-tar]
Saving to: `mysqlsla-2.03.tar.gz.2'

100%[===========================================================================================>] 33,674      50.2K/s   in 0.7s   

19:45:47 (50.2 KB/s) - `mysqlsla-2.03.tar.gz.2' saved [33674/33674]

2.解壓
[root@localhost tmp]# tar -zxvf mysqlsla-2.03.tar.gz
mysqlsla-2.03/
mysqlsla-2.03/Changes
mysqlsla-2.03/INSTALL
mysqlsla-2.03/README
mysqlsla-2.03/Makefile.PL
mysqlsla-2.03/bin/
mysqlsla-2.03/bin/mysqlsla
mysqlsla-2.03/META.yml
mysqlsla-2.03/lib/
mysqlsla-2.03/lib/mysqlsla.pm
mysqlsla-2.03/MANIFEST
[root@localhost tmp]# cd mysqlsla-2.03
[root@localhost mysqlsla-2.03]# ls
bin  Changes  INSTALL  lib  Makefile.PL  MANIFEST  META.yml  README

3.執行perl指令碼檢查包依賴關係
[root@localhost mysqlsla-2.03]# perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for mysqlsla

4.安裝
[root@localhost mysqlsla-2.03]# make && make install;
cp lib/mysqlsla.pm blib/lib/mysqlsla.pm
cp bin/mysqlsla blib/script/mysqlsla
/usr/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/mysqlsla
Manifying blib/man3/mysqlsla.3pm
Installing /usr/lib/perl5/site_perl/5.8.8/mysqlsla.pm
Installing /usr/share/man/man3/mysqlsla.3pm
Installing /usr/bin/mysqlsla
Writing /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/mysqlsla/.packlist
Appending installation info to /usr/lib/perl5/5.8.8/i386-linux-thread-multi/perllocal.pod
[root@localhost mysqlsla-2.03]#

5.簡單使用

文法:
 Slow log: mysqlsla -lt slow slow.log
 General log: mysqlsla -lt general general.log
 Binary log: mysqlbinlog bin.log | mysqlsla -lt binary -

這裡以slow log為例:

[root@localhost mysqlsla-2.03]# mysqlsla -lt slow /tmp/127_slow.log | more
Report for slow logs: /tmp/127_slow.log
24 queries total, 6 unique
Sorted by 't_sum'
Grand Totals: Time 16 s, Lock 1 s, Rows sent 18, Rows Examined 2.10M

______________________________________________________________________ 001 ___
Count         : 18  (75.00%)
Time          : 15 s total, 833.333 ms avg, 0 to 8 s max  (93.75%)
  95% of Time : 7 s total, 411.765 ms avg, 0 to 4 s max
Lock Time (s) : 0 total, 0 avg, 0 to 0 max  (0.00%)
  95% of Lock : 0 total, 0 avg, 0 to 0 max
Rows sent     : 0 avg, 0 to 0 max  (0.00%)
Rows examined : 116.51k avg, 8 to 1.05M max  (99.99%)
Database      :
Users         :
        root@localhost  : 100.00% (18) of query, 100.00% (24) of all users

Query abstract:
INSERT INTO t2 SELECT * FROM t2;

Query sample:
insert into t2 select * from t2;
........

選項說明:
總查詢次數 (queries total), 去重後的sql數量 (unique)
輸出報表的內容排序(sorted by)
最重大的慢sql統計資訊, 包括 平均執行時間, 等待鎖時間, 結果行的總數, 掃描的行總數.
Count, sql的執行次數及佔總的slow log數量的百分比.
Time, 執行時間, 包括總時間, 平均時間, 最小, 最大時間, 時間佔到總慢sql時間的百分比.
95% of Time, 去除最快和最慢的sql, 覆蓋率佔95%的sql的執行時間.
Lock Time, 等待鎖的時間.
95% of Lock , 95%的慢sql等待鎖時間.
Rows sent, 結果行統計數量, 包括平均, 最小, 最大數量.
Rows examined, 掃描的行數量.
Database, 屬於哪個資料庫
Users, 哪個使用者,IP, 佔到所有使用者執行的sql百分比
Query abstract, 抽象後的sql語句
Query sample, sql語句

mysqlsla常用參數說明:

1) -log-type (-lt) type logs:
通過這個參數來制定log的類型,主要有slow, general, binary, msl, udl,分析slow log時通過制定為slow.

2) -sort:
制定使用什麼參數來對分析結果進行排序,預設是按照t_sum來進行排序。
t_sum:按總時間排序
c_sum:按總次數排序
c_sum_p: sql語句執行次數佔總執行次數的百分比。

3) -top:
顯示sql的數量,預設是10,表示按規則取排序的前多少條

4) –statement-filter (-sf) [+-][TYPE]:
過濾sql語句的類型,比如select、update、drop.
[TYPE]有SELECT, CREATE, DROP, UPDATE, INSERT,例如"+SELECT,INSERT",不出現的預設是-,即不包括。

5) db:要處理哪個庫的日誌:

例如,只取backup庫的select語句、按c_sum_p排序的前2條記錄

[root@localhost mysqlsla-2.03]# mysqlsla -lt slow -sort c_sum_p  -sf  "+select" -db backup -top 2  /tmp/127_slow.log

Report for slow logs: /tmp/127_slow.log
4 queries total, 3 unique
Sorted by 'c_sum_p'
Grand Totals: Time 1 s, Lock 1 s, Rows sent 18, Rows Examined 195

______________________________________________________________________ 001 ___
Count         : 2  (50.00%)
Time          : 0 total, 0 avg, 0 to 0 max  (0.00%)
Lock Time (s) : 0 total, 0 avg, 0 to 0 max  (0.00%)
Rows sent     : 1 avg, 1 to 1 max  (11.11%)
Rows examined : 86 avg, 77 to 94 max  (87.69%)
Database      :
Users         :
        root@localhost  : 100.00% (2) of query, 100.00% (4) of all users

Query abstract:
SELECT SUM(format(duration,N)) AS duration FROM information_schema.profiling WHERE query_id=N;

Query sample:
select sum(format(duration,6)) as duration from information_schema.profiling where query_id=7;

______________________________________________________________________ 002 ___
Count         : 1  (25.00%)
Time          : 1 s total, 1 s avg, 1 s to 1 s max  (100.00%)
Lock Time (s) : 1 s total, 1 s avg, 1 s to 1 s max  (100.00%)
Rows sent     : 4 avg, 4 to 4 max  (22.22%)
Rows examined : 12 avg, 12 to 12 max  (6.15%)
Database      :
Users         :
        root@localhost  : 100.00% (1) of query, 100.00% (4) of all users

Query abstract:
SELECT * FROM tt WHERE a=N;

Query sample:
select * from tt where a=2;
[root@localhost mysqlsla-2.03]#

[root@localhost mysqlsla-2.03]#

--------end------- 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.