title: MySQL Optimization - MySQL's maximum memory usage is dangerously high, but still recommending increases
body: <p>I have a cPanel/CentOS 6.5 VM with 12 GB RAM.</p>
  
  <p>I ran the MySQLTuner script, and followed the recommendations that they gave, but it's still recommending increases, while telling me that MySQL's maximum memory usage is dangerously high.</p>
  
  <p>My current config in my my.cnf file is:</p>
  
  <pre><code>[mysqld]
  local-infile=0
  query_cache_size=32M
  innodb_file_per_table=1
  open_files_limit=6740
  default-storage-engine=MyISAM
  tmpdir=/mysqltmp
  group_concat_max_len=102400
  
  tmp_table_size=64M
  max_connections=500
  interactive_timeout=30
  wait_timeout=30
  thread_cache_size = 16
  thread_cache_size=16
  table_cache=2000
  join_buffer_size=32M
  query_cache_limit=512M
  key_buffer_size=128M
  max_heap_table_size=32M
  </code></pre>
  
  <p>I restarted MySQL a short while ago to apply my most recent changes.</p>
  
  <p>When I run the script, this is what I get:</p>
  
  <pre><code>      &gt;&gt;  MySQLTuner 1.3.0 - Major Hayden &lt;major@mhtx.net&gt;
   &gt;&gt;  Bug reports, feature requests, and downloads at http://mysqltuner.com/
   &gt;&gt;  Run with '--help' for additional options and output filtering
  [OK] Currently running supported MySQL version 5.5.36-cll
  [OK] Operating on 64-bit architecture
  
  -------- Storage Engine Statistics -------------------------------------------
  [--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MRG_MYISAM
  [--] Data in MyISAM tables: 551M (Tables: 467)
  [--] Data in InnoDB tables: 49M (Tables: 908)
  [--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
  [--] Data in MEMORY tables: 0B (Tables: 37)
  [!!] Total fragmented tables: 17
  
  -------- Security Recommendations  -------------------------------------------
  [OK] All database users have passwords assigned
  
  -------- Performance Metrics -------------------------------------------------
  [--] Up for: 2h 6m 33s (379K q [49.933 qps], 2K conn, TX: 390M, RX: 115M)
  [--] Reads / Writes: 51% / 49%
  [--] Total buffers: 336.0M global + 34.6M per thread (500 max threads)
  [!!] Maximum possible memory usage: 17.2G (148% of installed RAM)
  [OK] Slow queries: 0% (0/379K)
  [OK] Highest usage of available connections: 1% (5/500)
  [OK] Key buffer size / total MyISAM indexes: 128.0M/125.7M
  [OK] Key buffer hit rate: 100.0% (4M cached / 1K reads)
  [OK] Query cache efficiency: 58.0% (145K cached / 251K selects)
  [!!] Query cache prunes per day: 892777
  [OK] Sorts requiring temporary tables: 0% (0 temp sorts / 10K sorts)
  [!!] Joins performed without indexes: 3054
  [!!] Temporary tables created on disk: 29% (6K on disk / 20K total)
  [OK] Thread cache hit rate: 99% (5 created / 2K connections)
  [OK] Table cache hit rate: 95% (1K open / 1K opened)
  [OK] Open file limit used: 14% (999/6K)
  [OK] Table locks acquired immediately: 99% (261K immediate / 261K locks)
  [OK] InnoDB buffer pool / data size: 128.0M/49.1M
  [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
      Enable the slow query log to troubleshoot bad queries
      Adjust your join queries to always utilize indexes
      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 (&gt; 32M)
      join_buffer_size (&gt; 32.0M, or always use indexes with joins)
      tmp_table_size (&gt; 64M)
      max_heap_table_size (&gt; 32M)
  </code></pre>
  
  <p>If I increase those variables, I'll be even higher with memory usage.</p>
  
  <p>Does anyone have any recommendations with what to do now?</p>
  
  <p>EDIT: Here are the results 14 hours after the last MySQL restart:</p>
  
  <pre><code> &gt;&gt;  MySQLTuner 1.3.0 - Major Hayden &lt;major@mhtx.net&gt;
   &gt;&gt;  Bug reports, feature requests, and downloads at http://mysqltuner.com/
   &gt;&gt;  Run with '--help' for additional options and output filtering
  [OK] Currently running supported MySQL version 5.5.36-cll
  [OK] Operating on 64-bit architecture
  
  -------- Storage Engine Statistics -------------------------------------------
  [--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MRG_MYISAM
  [--] Data in MyISAM tables: 552M (Tables: 467)
  [--] Data in InnoDB tables: 49M (Tables: 908)
  [--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
  [--] Data in MEMORY tables: 0B (Tables: 37)
  [!!] Total fragmented tables: 21
  
  -------- Security Recommendations  -------------------------------------------
  [OK] All database users have passwords assigned
  
  -------- Performance Metrics -------------------------------------------------
  [--] Up for: 14h 2m 3s (1M q [20.830 qps], 9K conn, TX: 1B, RX: 281M)
  [--] Reads / Writes: 56% / 44%
  [--] Total buffers: 336.0M global + 34.6M per thread (500 max threads)
  [!!] Maximum possible memory usage: 17.2G (148% of installed RAM)
  [OK] Slow queries: 0% (0/1M)
  [OK] Highest usage of available connections: 1% (5/500)
  [OK] Key buffer size / total MyISAM indexes: 128.0M/125.9M
  [OK] Key buffer hit rate: 100.0% (15M cached / 1K reads)
  [OK] Query cache efficiency: 76.3% (625K cached / 820K selects)
  [!!] Query cache prunes per day: 250933
  [OK] Sorts requiring temporary tables: 0% (0 temp sorts / 35K sorts)
  [!!] Joins performed without indexes: 8623
  [!!] Temporary tables created on disk: 31% (26K on disk / 82K total)
  [OK] Thread cache hit rate: 99% (5 created / 9K connections)
  [OK] Table cache hit rate: 58% (2K open / 3K opened)
  [OK] Open file limit used: 17% (1K/6K)
  [OK] Table locks acquired immediately: 99% (469K immediate / 469K locks)
  [OK] InnoDB buffer pool / data size: 128.0M/49.1M
  [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
      Enable the slow query log to troubleshoot bad queries
      Adjust your join queries to always utilize indexes
      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 (&gt; 32M)
      join_buffer_size (&gt; 32.0M, or always use indexes with joins)
      tmp_table_size (&gt; 64M)
      max_heap_table_size (&gt; 32M)
  </code></pre>
  
  <p>Thanks a lot!</p>