MySQL my.cnf Performance Tuning

By | 2012/05/29

Debian and Ubuntu include a package called mysqltuner which can analyze your MySQL database and provide some performance metrics as well as tuning advice for my.cnf. Here is how it works!

Install mysqltuner:

$ sudo apt-get install mysqltuner

Run the app, it will prompt for your MySQL admin credentials. Looks like I need to bump up my key_buffer_size value. 🙂

$ mysqltuner 

 >>  MySQLTuner 1.0.1 - Major Hayden 
 >>  Bug reports, feature requests, and downloads at
 >>  Run with '--help' for additional options and output filtering
Please enter your MySQL administrative login: xxxxxx
Please enter your MySQL administrative password: 

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.62-0ubuntu0.10.04.1
[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: 23M (Tables: 167)
[--] Data in InnoDB tables: 128K (Tables: 8)
[!!] Total fragmented tables: 32

-------- Performance Metrics -------------------------------------------------
[--] Up for: 33d 20h 11m 14s (57M q [19.810 qps], 1M conn, TX: 312B, RX: 6B)
[--] Reads / Writes: 99% / 1%
[--] Total buffers: 27.0M global + 5.3M per thread (100 max threads)
[OK] Maximum possible memory usage: 558.3M (55% of installed RAM)
[OK] Slow queries: 0% (6/57M)
[OK] Highest usage of available connections: 74% (74/100)
[!!] Key buffer size / total MyISAM indexes: 16.0K/8.0M
[!!] Key buffer hit rate: 74.3% (148M cached / 38M reads)
[OK] Query cache efficiency: 75.9% (38M cached / 50M selects)
[!!] Query cache prunes per day: 328760
[OK] Sorts requiring temporary tables: 0% (402 temp sorts / 1M sorts)
[!!] Temporary tables created on disk: 49% (590K on disk / 1M total)
[OK] Thread cache hit rate: 99% (597 created / 1M connections)
[!!] Table cache hit rate: 0% (4 open / 2M opened)
[OK] Open file limit used: 0% (8/1K)
[OK] Table locks acquired immediately: 99% (14M immediate / 14M locks)
[OK] InnoDB data size / buffer pool: 128.0K/8.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    Enable the slow query log to troubleshoot bad queries
    When making adjustments, make tmp_table_size/max_heap_table_size equal
    Reduce your SELECT DISTINCT queries without LIMIT clauses
    Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
    key_buffer_size (> 8.0M)
    query_cache_size (> 1M)
    tmp_table_size (> 16M)
    max_heap_table_size (> 16M)
    table_cache (> 4)