MySQLのチューニング

mysql 開発ツール

最近ちょこちょここのサーバーが落ちるのでMySQLをチューニングをしてみました。
アクセスもないのに落ちるので設定の問題なのかは不明っす

MySQLTuner

便利な世の中で、こうした方がいいよと教えてくれるツールがあるのでありがたく使います
major/MySQLTuner-perl

インストール

インストールする必要はなく、githubからファイルを落としてくれば使えます
簡単なのはcloneしちゃうことですね
~~~
git clone [email protected]:major/MySQLTuner-perl.git
cd MySQLTuner-perl
~~~

実行する

mysqltuner.plを実行するだけでOKです

~~~
perl mysqltuner.pl
~~~

実行結果

色々ずらーっとでます

~~~

>> MySQLTuner 1.3.0 – Major Hayden
>> 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:
[OK] Currently running supported MySQL version 5.5.38-log
[OK] Operating on 64-bit architecture

——– Storage Engine Statistics ——————————————-
[–] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MRG_MYISAM
[–] Data in MyISAM tables: 26M (Tables: 21)
[–] Data in InnoDB tables: 110M (Tables: 276)
[–] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[!!] Total fragmented tables: 277

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

——– Performance Metrics ————————————————-
[–] Up for: 3h 3m 41s (29K q [2.693 qps], 1K conn, TX: 39M, RX: 6M)
[–] Reads / Writes: 91% / 9%
[–] Total buffers: 560.0M global + 12.4M per thread (151 max threads)
[!!] Maximum possible memory usage: 2.4G (129% of installed RAM)
[OK] Slow queries: 0% (0/29K)
[OK] Highest usage of available connections: 10% (16/151)
[OK] Key buffer size / total MyISAM indexes: 384.0M/12.7M
[OK] Key buffer hit rate: 97.0% (641K cached / 19K reads)
[OK] Query cache efficiency: 34.7% (6K cached / 20K selects)
[!!] Query cache prunes per day: 141
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 5K sorts)
[!!] Temporary tables created on disk: 40% (2K on disk / 6K total)
[OK] Thread cache hit rate: 98% (20 created / 1K connections)
[OK] Table cache hit rate: 49% (85 open / 172 opened)
[OK] Open file limit used: 4% (49/1K)
[OK] Table locks acquired immediately: 99% (20K immediate / 20K locks)
[OK] InnoDB buffer pool / data size: 128.0M/110.6M
[OK] InnoDB log waits: 0
——– Recommendations —————————————————–
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours – recommendations may be inaccurate
Reduce your overall MySQL memory footprint for system stability
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries without LIMIT clauses
Variables to adjust:
*** MySQL’s maximum memory usage is dangerously high ***
*** Add RAM before increasing MySQL buffer variables ***
query_cache_size (> 16M)
tmp_table_size (> 16M)
max_heap_table_size (> 16M)
~~~

チューニングする

あとは指示を参考に調整していきます
どうやらでっかいクエリがあってメモリに載っかってないよ、と言われているようなのでこの項目を変更・・・

~~~
*** Add RAM before increasing MySQL buffer variables ***
query_cache_size (> 16M)
tmp_table_size (> 16M)
max_heap_table_size (> 16M)
~~~

すると、今度は別の項目が〜となっていくので良きところまで繰り返し直してしゅーりょー

参考サイト
MySQLTunerを使ってMySQLを診断しよう! | ADMAGE blog
MySQLのメモリ関係のシステム変数 – 祈れ、そして働け ~ Ora et labora

コメント

タイトルとURLをコピーしました