天天看點

percona-toolkit學習筆記(七)

功能:

    模拟切割檔案并通過管道傳遞給先入先出隊列而不用真正的切割檔案

說明:

    pt-fifo-split讀取大檔案中的資料并列印到fifo檔案,每次達到指定行數就往fifo檔案中列印一個EOF字元,讀取完成以後,關閉掉fifo檔案并移走,然後重建fifo檔案,列印更多的行。這樣可以保證你每次讀取的時候都能讀取到制定的行數直到讀取完成。注意此工具隻能工作在類unix作業系統。這個程式對大檔案的資料導入資料庫非常有用,具體參考:https://www.percona.com/blog/2008/07/03/how-to-load-large-files-safely-into-innodb-with-load-data-infile/

執行個體:

    一次讀取100行記錄

    pt-fifo-split--lines 100 /root/all.sql

    while[ -e /tmp/pt-fifo-split ]; do cat /tmp/pt-fifo-split; done

功能:Find MySQL tables and executeactions, like GNU find

    pt-findsearches for MySQL tables and executes actions, like GNU find.  The default action is to print the databaseand table name.

pt-find --ctime -1 --engine MyISAM-uroot -proot -h localhost  # 列出建立時間小于1天且使用MyISAM引擎的資料表

pt-find --engine InnoDB -uroot-proot -h localhost              # 列出InnoDB引擎的表

pt-find --ctime -1 -uroot -proot-h localhost --exec-plus "drop table %s"  # 将找到的符合條件的table删除掉

pt-find --tablesize +500M -uroot-proot -h localhost               # 列出總大小超過500M的表

pt-find hellodb -uroot -proot -hlocalhost       # 列出hellodb庫裡的所有表

pt-find --printf"%T\t%D.%N\n"  -uroot -proot -hlocalhost | sort -rn # 列出所有表的total data and index size,并從大到小排序

功能:Convert queries into fingerprints.

       用于生成查詢指紋。主要将将sql查詢生成queryID,pt-query-digest中的ID即是通過此工具來完成的。

       類似于Oracle中的SQL_ID,涉及綁定變量,字面量等

    #pt-fingerprint --query "select a,b,c from hellodb.students wherestuid=22"

功能:pt-ioprofile的原理是對某個pid附加一個strace程序進行IO分析

    pt-ioprofileuses "strace" and "lsof" to watch a process’s IO and printout a table of files and I/O activity. By default, it watches the mysqld process for 30 seconds.

功能:Kill掉符合指定條件mysql語句

官方示例:

Kill queries runninglonger than 60s:

# pt-kill --busy-time 60 --kill

Print, do not kill,queries running longer than 60s:

# pt-kill --busy-time 60 --print

Check for sleepingprocesses and kill them all every 10s:

# pt-kill --match-command Sleep--kill --victims all --interval 10

Print all loginprocesses:

# pt-kill --match-state login--print --victims all

See which queries inthe processlist right now would match:

# mysql -e "SHOWPROCESSLIST" > proclist.txt

# pt-kill --test-matchingproclist.txt --busy-time 60 --print

功能:用于收集mysql資料庫故障時的相關資訊便于後續診斷處理。Collect forensic data about MySQLwhen problems occur

pt-stalk等待觸發條件觸發,然後收集資料幫助錯誤診斷,它被設計成使用root權限運作的守護程序,是以你可以診斷那些你不能直接觀察的間歇性問題。預設的診斷觸發條件為SHOW GLOBAL STATUS。也可以指定processlist為診斷觸發條件,使用--function參數指定。

範例1:指定診斷觸發條件為status,同時運作語句超過20的時候觸發,收集的資料存放在/tmp/test目錄下:

# pt-stalk  --function status \

--variable Threads_running--threshold 20 \

--dest /tmp/test -- -uroot -proot -h192.168.2.11

範例2:指定診斷觸發條件為processlist,超過20個狀态為statistics觸發,收集的資料存放在/tmp/test目錄下:

# pt-stalk  --function processlist \

--variable State --matchstatistics --threshold 20 \

本文轉自 lirulei90 51CTO部落格,原文連結:http://blog.51cto.com/lee90/1772205,如需轉載請自行聯系原作者