MySQL Tuning İçin Hazır Script



Sunucunuzda MySQL’in çok fazla işlemci ve memory harcadığını görüyorsanız aşağıdaki scripti kurarak olası nedenleri inceleyebilirsiniz:

# cd ~
# wget https://raw.github.com/rackerhacker/MySQLTuner-perl/master/mysqltuner.pl
# chmod 777 mysqltuner.pl
# ./mysqltuner.pl

Çıktısı sunucunuzda değişebileceği gibi bizdeki örnekte şekildedir:

root@server [~]# ./mysqltuner.pl

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.63-cll
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 65M (Tables: 395)
[--] Data in InnoDB tables: 357M (Tables: 278)
[!!] Total fragmented tables: 53

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

-------- Performance Metrics -------------------------------------------------
[--] Up for: 20h 54m 42s (2M q [28.036 qps], 87K conn, TX: 300B, RX: 146M)
[--] Reads / Writes: 97% / 3%
[--] Total buffers: 34.0M global + 2.7M per thread (151 max threads)
[OK] Maximum possible memory usage: 449.2M (45% of installed RAM)
[OK] Slow queries: 0% (310/2M)
[OK] Highest usage of available connections: 9% (14/151)
[OK] Key buffer size / total MyISAM indexes: 8.0M/16.5M
[OK] Key buffer hit rate: 99.9% (7M cached / 5K reads)
[!!] Query cache is disabled
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 72K sorts)
[OK] Temporary tables created on disk: 7% (1K on disk / 15K total)
[!!] Thread cache is disabled
[!!] Table cache hit rate: 1% (64 open / 5K opened)
[OK] Open file limit used: 7% (74/1K)
[OK] Table locks acquired immediately: 99% (1M immediate / 1M locks)
[!!] InnoDB data size / buffer pool: 357.1M/8.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours - recommendations may be inaccurate
Enable the slow query log to troubleshoot bad queries
Set thread_cache_size to 4 as a starting value
Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
query_cache_size (>= 8M)
thread_cache_size (start at 4)
table_cache (> 64)
innodb_buffer_pool_size (>= 357M)

Çıktıdan görülebileceği gibi MySQL veritabanını defragment etmemiz gerekiyor ve query cache’i enable ederek %97’ye %3 olan okuma/yazma işlemlerini hızlandırabiliriz. InnoDB’nin ayarlarını da incelemek gerekir.

Muzaffer Seha Çuhadar