Maatkit工具簡介

一、maatkit工具集簡介
maatkit包含多個MySQL的輔助工具,使用它們,可以讓你的MySQL服務器使用起來更加方便也更加安全。其實它提供的大部分工具本身就應該是MySQL應該提供的,但是由於各種原因,MySQL更專注於數據庫本身的性能和功能的增強,而忽略了這些方面工具的提供,好在percona和其他一些對MySQL本身功能仍然不滿足公司組織發起並維護了maatkit項目,他們的貢獻和使用進一步促進了maatkit的進步和發展。
maatkit的另外一個好處就是,他是開源的,是一個Free software。你可以自由的改進軟件並將自己作出的改進版本向社會發行傳播。它遵循GPL協議 。如何獲得支持和服務是衆所周知的自由軟件的問題,但是對maatkit來說,也不是大問題。你可以通過google project獲得免費的幫助,如果仍然不夠,你甚至可以直接通過percona聯繫原作者,獲得MySQL性能優化的專家顧問們的幫助。maatkit考慮到自身工具的數量問題,爲了減輕它的複雜度,也簡化使用者學習的難度,maatkit所有的工具的選項和參數都保持統一的標準(而且大部分參數和MySQL的命令行客戶端保持一致),基本上,你會用了一個工具,其他工具的學習和了解也差不多。這樣大大減輕了使用者的負擔也加速了我們的學習過程。真是由於maatkit的這麼多優勢,它目前已經隨Debian和CentOS等許多GNU/linux distributions一起發佈。

下面我們先來簡單瞭解一下maatkit包含的工具集爲MySQL提供了哪些振奮人心的新特性和新功能。maatkit工具目前包含26個不同功能的工具。相應的工具名及其功能簡介如下:
1.mk-archiver 
將MySQL表中的一些行數據庫歸檔到另外一個表或者文件中。Archive rows from a MySQL table into another table or a file.
2.mk-audit 
對MySQL配置,架構和操作進行分析,彙總並生成報告。Analyze, summarize and report on MySQL config, schema and operation
3.mk-checksum-filter 
過濾mk-table-checksum生成的checksums。Filter checksums from mk-table-checksum.
4.mk-deadlock-logger 
抽取和記錄MySQL死鎖信息。Extract and log MySQL deadlock information.
5.mk-duplicate-key-checker 
查找MySQL表中重複的索引和外鍵索引。Find duplicate indexes and foreign keys on MySQL tables.
6.mk-fifo-split 
Split files and pipe lines to a fifo without really splitting.暫時沒有被包含在fedora 11的源包中。
7.mk-find 
類似於GNU的find工具,用於查找MySQL表和執行動作。Find MySQL tables and execute actions, like GNU find.
8.mk-heartbeat 
監控MySQL replication延遲時間。Monitor MySQL replication delay.
9.mk-kill 
kill掉符合某一條件的MySQL queries。Kill MySQL queries that match certain criteria.暫時沒有被包含在fedora 11的源包中。
10.mk-loadavg 
監控MySQL負載並在負載過大時採取某些動作。Watch MySQL load and take action when it gets too high. 暫時沒有被包含在fedora 11的源包中。
11.mk-log-player 
分割並重現MySQL的slow logs。Split and play MySQL slow logs. 暫時沒有被包含在fedora 11的源包中。
12.mk-parallel-dump 
以並行的方式dump MySQL的多個表。Dump sets of MySQL tables in parallel.
13.mk-parallel-restore 
以並行的方式將文件Load到MySQL中去。Load files into MySQL in parallel.
14.mk-profile-compact 
壓縮mk-query-profiler的輸出。Compact the output from mk-queryprofiler.
15.mk-query-digest 
解析日誌和相關資料。分析,轉換,過濾,複審queries,並生成報告。Parses logs and more. Analyze, transform, filter, review and report on queries.暫時沒有被包含在fedora 11的源包中。存在另外的mk-log-parser工具。
16.mk-query-profiler 
執行SQL語句並打印統計信息,或者評估其他進程的活動。Execute SQL statements and print statistics, or measure activity caused by other processes.
17.mk-show-grants 
規範話和打印MySQL授權信息。這樣你可以更有效的複製,比較他們,也可以更好的對他們進行版本控制。Canonicalize and print MySQL grants so you can effectively replicate, compare and version-control them.
18.mk-slave-delay 
控制MySQL slave端,使它滯後於其master。Make a MySQL slave server lag behind its master.
19.mk-slave-find 
找出並打印MySQL和其slave的層級關係樹模型。Find and print replication hierarchy tree of MySQL slaves.
20.mk-slave-move 
在MySQL replication層級關係中移動某一個MySQL slave。Move a MySQL slave around in the replication hierarchy.
21.mk-slave-prefetch 
將relay log傳給MySQL slave以便預熱緩存。Pipeline relay logs on a MySQL slave to pre-warm caches.
22.mk-slave-restart 
監控MySQL replication並在其出現錯誤時重啓replication。Watch and restart MySQL replication after errors.
23.mk-table-checksum 
利用它可以對在線的replication進行一致性檢查,或者有效地計算一個或多個服務器上的MySQL表的校驗和。Perform an online replication consistency check, or checksum MySQL tables efficiently on one or many servers.
24.mk-table-sync 
有效地同步MySQL的表。Synchronize MySQL tables efficiently.
25.mk-upgrade 
在兩個MySQL server上提交SQL語句,並比較運行結果。Execute SQL statements against two MySQL servers and compare the results. 暫時沒有被包含在fedora 11的源包中。
26.mk-visual-explain 
將EXPLAIN的輸出打印成樹狀結構。Format EXPLAIN output as a tree.

注意:上面的各項工具及其相應的功能主要翻譯自maatkit的官方文檔。其中:mk-fifo-split,mk-kill,mk-loadavg,mk-log-player,mk-query-digest,mk-upgrade暫時沒有包含在fedora的源中,而fedora的源中包含另外一個官方文檔中不存在的工具mk-log-parser工具。

詳細請參照:
http://hatemysql.com/2010/06/10/maatkit-%E7%AE%80%E4%BB%8B/
http://www.percona.com/

二、安裝Maatkit
Maatkit是一個Perl寫的Mysql開源管理工具,根據調查全球大約有70%多的Mysql管理員使用這個工具來管理Mysql,但國內很少有人知道這個工具,因此介紹這個工具。首先安裝Maatkt,需要Perl,DBI,DBD::mysql相關模塊。
1.perl
perl -v
This is perl, v5.8.5 built for i386-linux-thread-multi
Copyright 1987-2004, Larry Wall
一般linux安裝的時候默認安裝了perl。
2.Mysql安裝(省略)
3.DBI,可以到這裏下載相應的版本
tar zxf DBI-1.58.tar.gz
cd DBI-1.58
perl Makefile.pl
make
make test
make
make install
4.data-showtable包
gzip -c -d Data-ShowTable-x.xx.tar.gz | tar xvf -
cd Data-ShowTable-x.xx
perl Makefile.PL
make
不要試make test,測試套件損壞了!
make install
5.msql-mysql-modules 
gzip -c -d Msql-Mysql-modules-x.xx.tar.gz | tar xvf -
將壓縮文件接壓縮到一個名爲Msql-Mysql-modules-x.xx的目錄。
cd Msql-Mysql-modules-x.xx
perl Makefile.PL
在 "perl Makefile.PL" 期間,會向你提出一些問題。特別是你必須選擇安裝驅動器(MySQL, mSQL2 and/or mSQL1)。
MySQL驅動程序叫DBD::mysql,單獨的mSQL驅動程序叫DBD::mSQL。如果你想支持mSQL1和mSQL2,用DBD::mSQL1。
make
make test
make install
6.DBD-mysql
安裝DBD: DBD-mysql-4.005
perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config
make
make test
make
make install
如果出現以下錯誤:
install_driver(mysql) failed: Can't load '/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/DBD/mysql/mysql.so' for module DBD::mysql: libmysqlclient.so.12: cannot open shared object file: No such file or directory at /usr/lib/perl5/5.8.5/i386-linux-thread-multi/DynaLoader.pm line 230.
at (eval 6) line 3
Compilation failed in require at (eval 6) line 3.
Perhaps a required shared library or dll isn't installed where expected at /root/mysqlreport line 162
就做操作:
cp /usr/local/mysql/include/mysql* /usr/include/
cp /usr/local/mysql/lib/* /usr/lib/ (64位的是lib64)
然後再重新安裝DBD: DBD-mysql-4.005
perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config
make
make test
make install
7.安裝maatkit
tar zxvf   maatkit-2325.tar.gz
cd maatkit-2325
perl Makefile.PL
make install
下面分別列出這套工具,以及官方的定義,在後續的文章中,會分別對這些工具進行介紹,以及自己的測試和心得體會。
mk-archiver Archive rows from a MySQL table into another table or a file.
mk-audit Analyze, summarize and report on MySQL config, schema and operation
mk-checksum-filter Filter checksums from mk-table-checksum.
mk-deadlock-logger Extract and log MySQL deadlock information.
mk-duplicate-key-checker Find duplicate keys and foreign keys on MySQL tables.
mk-fifo-split Split files and pipe lines to a fifo without really splitting.
mk-find Find MySQL tables and execute actions, like GNU find.
mk-heartbeat Monitor MySQL replication delay.
mk-log-player Split and play MySQL slow logs.
mk-log-server Serve MySQL binary logs.
mk-parallel-dump Dump sets of MySQL tables in parallel.
mk-parallel-restore Load files into MySQL in parallel.
mk-profile-compact Compact the output from mk-query-profiler.
mk-query-digest Parses logs and more. Analyze, transform, filter, review and report on queries.
mk-query-profiler Execute SQL statements and print statistics, or measure activity caused by other processes.
mk-show-grants Canonicalize and print MySQL grants so you can effectively replicate, compare and version-control them.
mk-slave-delay Make a MySQL slave server lag behind its master.
mk-slave-find Find and print replication hierarchy tree of MySQL slaves.
mk-slave-move Move a MySQL slave around in the replication hierarchy.
mk-slave-prefetch Pipeline relay logs on a MySQL slave to pre-warm caches.
mk-slave-restart Watch and restart MySQL replication after errors.
mk-table-checksum Perform an online replication consistency check, or checksum MySQL tables efficiently on one or many servers.
mk-table-sync Synchronize MySQL tables efficiently.
mk-visual-explain Format EXPLAIN output as a tree.

原文來自:http://www.bigheaddba.net/
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章