よかろうもん!

アプリからインフラまで幅広くこなすいまどきのクラウドエンジニアが記す技術ブログ

MySQLTunerを試してみた

RSSをチェックしてて、MySQL Tunerなるものがあるということを知ったので、さっそく試してみました。
利用するにはリポジトリからperlスクリプトをチェックアウトしてくるだけでOKです。

$ mkdir -p ~/tools/mysql-tuner
$ cd ~/tools/mysql-tuner
$ svn co http://tools.assembla.com/svn/mysqltuner/ .
$ chmod +x mysqltuner.pl

では、まずはhelpを見てどのようなオプションがあるのかを確認してみます。

$ ./mysqltuner.pl --help

MySQLTuner 0.9.9 - MySQL High Performance Tuning Script
Bug reports, feature requests, and downloads at http://mysqltuner.com/
Maintained by Major Hayden (major@mhtx.net) - Licensed under GPL

Important Usage Guidelines:
To run the script with the default options, run the script without arguments
Allow MySQL server to run for at least 24-48 hours before trusting suggestions
Some routines may require root level privileges (script will provide warnings)
You must provide the remote server's total memory when connecting to other servers

Connection and Authentication
--host Connect to a remote host to perform tests (default: localhost)
--socket Use a different socket for a local connection
--port Port to use for connection (default: 3306)
--user Username to use for authentication
--pass Password to use for authentication

Performance and Reporting Options
--skipsize Don't enumerate tables and their types/sizes (default: on)
(Recommended for servers with many tables)
--checkversion Check for updates to MySQLTuner (default: don't check)
--forcemem Amount of RAM installed in megabytes
--forceswap Amount of swap memory configured in megabytes

Output Options:
--nogood Remove OK responses
--nobad Remove negative/suggestion responses
--noinfo Remove informational responses
--nocolor Don't print output in color

まぁ、今回はローカルにインストールしてあるMySQLサーバで認証もまだ設定していないので、オプションなしで試してみます>。
#いくつかの項目でrootで実行しろ!というコメントが出てくるので、sudo で実行しましょう

$ sudo ./mysqltuner.pl

> MySQLTuner 0.9.9 - Major Hayden
> Bug reports, feature requests, and downloads at http://mysqltuner.com/
> Run with '--help' for additional options and output filtering
[!!] Successfully authenticated with no password - SECURITY RISK!

                • General Statistics --------------------------------------------------

[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.0.51a-3ubuntu5.1
[OK] Operating on 64-bit architecture

                • Storage Engine Statistics -------------------------------------------

[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 0B (Tables: 1)
[--] Data in InnoDB tables: 3M (Tables: 131)
[OK] Total fragmented tables: 0

                • Performance Metrics -------------------------------------------------

[--] Up for: 2h 46m 25s (155K q [15.610 qps], 612 conn, TX: 51M, RX: 18M)
[--] Reads / Writes: 64% / 36%
[--] Total buffers: 58.0M global + 2.6M per thread (100 max threads)
[OK] Maximum possible memory usage: 320.5M (16% of installed RAM)
[OK] Slow queries: 0% (0/155K)
[OK] Highest usage of available connections: 31% (31/100)
[OK] Key buffer size / total MyISAM indexes: 16.0M/2.2M
[!!] Key buffer hit rate: 68.9% (7K cached / 2K reads)
[OK] Query cache efficiency: 40.2% (41K cached / 103K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 4K sorts)
[!!] Joins performed without indexes: 101
[OK] Temporary tables created on disk: 25% (7K on disk / 29K total)
[OK] Thread cache hit rate: 94% (35 created / 612 connections)
[!!] Table cache hit rate: 7% (64 open / 861 opened)
[OK] Open file limit used: 0% (4/1K)
[OK] Table locks acquired immediately: 100% (127K immediate / 127K locks)
[!!] Connections aborted: 8%
[OK] InnoDB data size / buffer pool: 3.2M/8.0M

                • Recommendations -----------------------------------------------------

General recommendations:
Add skip-innodb to MySQL configuration to disable InnoDB
MySQL started within last 24 hours - recommendations may be inaccurate
Enable the slow query log to troubleshoot bad queries
Adjust your join queries to always utilize indexes
Increase table_cache gradually to avoid file descriptor limits
Your applications are not closing MySQL connections properly
Variables to adjust:
join_buffer_size (> 128.0K, or always use indexes with joins)
table_cache (> 64)

出力の結果で確認すべき箇所ですが、どうやら[!!]がWARNINGにあたるようで、本番環境で利用する場合は、これらの項目はなくすようにしましょう。
また、各項目ついては、MySQLサーバの性能値などが出力されていますので、それらを確認してください。

実際に使ってみた感想ですが、予想していたよりも情報が少ないですね。
設定内容を含めた現状確認で利用できる程度で、これだけの情報でチューニングがバリバリできるというわけではなさそうですね。確かに、必要な情報は取得できますが…。
まぁ、まだバージョンも0.99だし、これからなのかもしれませんね。
#ちなみに今回の計測対象MySQLは、導入したばかりでほとんど利用してませんので、その点はご理解ください。