エントリー

MySQLを少しだけチューニング

phpMyAdminでDBの状態を見てみると赤字で調整を伺わす項目がある

23456

プログラム側の調整は単純には無理なのでDB側を少し調整してみることにする

今回は玄箱HGの実装メモリが128Mということもあり時間もかけたくないので、高度なチューンは考えないでMySQLTunerというツールmysqltuner.plを利用

$ wget http://mysqltuner.com/mysqltuner.pl
(目的の物が取得できなかったのでブラウザで持ってきた)
(以下で取得可能:https://github.com/major/MySQLTuner-perl)
$ wget https://github.com/rackerhacker/MySQLTuner-perl/archive/master.zip
(略)
$ unzip
master.zip
Archive: master.zip
d9eef7d75241e675469117b21b910e5b3d58dfa9
creating: MySQLTuner-perl-master/
inflating: MySQLTuner-perl-master/LICENSE
inflating: MySQLTuner-perl-master/README.md
inflating: MySQLTuner-perl-master/mysqltuner.pl
(ここまで)

$ perl mysqltuner.pl

 >> MySQLTuner 1.2.0 - Major Hayden <major@mhtx.net>
 >> Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >> Run with '--help' for additional options and output filtering
Please enter your MySQL administrative login:
Please enter your MySQL administrative password:
[!!] Attempted to use login credentials, but they were invalid.
hero@KURO-BOX:~$ perl mysqltuner.pl

 >> MySQLTuner 1.2.0 - Major Hayden <major@mhtx.net>
 >> Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >> Run with '--help' for additional options and output filtering
Please enter your MySQL administrative login:
Please enter your MySQL administrative password:

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.63-0+squeeze1
[OK] Operating on 32-bit architecture with less than 2GB RAM

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 3M (Tables: 46)
[!!] InnoDB is enabled but isn't being used
[!!] Total fragmented tables: 12

-------- Security Recommendations -------------------------------------------
[OK] All database users have passwords assigned

-------- Performance Metrics -------------------------------------------------
[--] Up for: 11d 8h 34m 57s (214K q [0.219 qps], 3K conn, TX: 152M, RX: 25M)
[--] Reads / Writes: 54% / 46%
[--] Total buffers: 74.0M global + 3.1M per thread (151 max threads)
[!!] Maximum possible memory usage: 536.4M (432% of installed RAM)
[OK] Slow queries: 0% (2/214K)
[OK] Highest usage of available connections: 5% (8/151)
[OK] Key buffer size / total MyISAM indexes: 32.0M/1.3M
[!!] Query cache efficiency: 1.8% (860 cached / 47K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 15K sorts)
[OK] Temporary tables created on disk: 10% (1K on disk / 10K total)
[OK] Thread cache hit rate: 99% (18 created / 3K connections)
[!!] Table cache hit rate: 2% (64 open / 2K opened)
[OK] Open file limit used: 12% (128/1K)
[OK] Table locks acquired immediately: 100% (573 immediate / 573 locks)

-------- Recommendations -----------------------------------------------------
General recommendations:
 Add skip-innodb to MySQL configuration to disable InnoDB
 Run OPTIMIZE TABLE to defragment tables for better performance
 Reduce your overall MySQL memory footprint for system stability
 Enable the slow query log to troubleshoot bad queries
 Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
 *** MySQL's maximum memory usage is dangerously high ***
 *** Add RAM before increasing MySQL buffer variables ***
 query_cache_limit (> 1M, or use smaller result sets)
 table_cache (> 128)

Recommendations以降がお勧め設定値になる

上記はphpMyAdminの警告でテーブルキャッシュを128にした後のチェックであるがそれでも不足らしい
MySQLが使用メモリが多くて危険なのでバッファーを増やす前にメモリを増設とあるが少し増やして、

# vi /etc/mysql/my.cnf
table_cache = 192
query_cache_limit = 2M
# service mysql restart
・・・
# mysqladmin -u root -p variables
(略)

これでしばらく様子を見ることにする

尚、MySQLリファレンスマニュアルによると、サーバをチューニングする際に使用される最も重要な変数はkey_buffer_sizeと table_open_cacheの2つで、他の変数の変更を行う前にこの変数をあらかじめ適切に設定しておくこととある

ページ移動

コメント

  • コメントはまだありません。

コメント登録

  • コメントを入力してください。
登録フォーム
名前
メールアドレス
URL
コメント
閲覧制限
投稿キー(スパム対策に、投稿キー を半角で入力してください。)

ユーティリティ

検索

エントリー検索フォーム
キーワード

新着コメント

過去ログ

Feed