MySQL tables are often fragmented and most of the clients/devs don’t give a f’ about it! They ‘re happy just to blame the sysadmin. So since you’re not a DBA you can’t do magic, but you can optimize these tables for them.
For that puprose I use mysqltuner which is written in perl, download it from here. This tool will give you a good overview about your mysql server’s condition.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
>> MySQLTuner 1.4.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 [OK] Logged in using credentials from debian maintenance account. [OK] Currently running supported MySQL version 5.5.43-0ubuntu0.14.04.1 [OK] Operating on 64-bit architecture -------- Storage Engine Statistics ------------------------------------------- [--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MRG_MYISAM [--] Data in MEMORY tables: 0B (Tables: 8) [--] Data in MyISAM tables: 402M (Tables: 427) [--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17) [--] Data in InnoDB tables: 82M (Tables: 433) [!!] Total fragmented tables: 22 -------- Security Recommendations ------------------------------------------- [OK] All database users have passwords assigned -------- Performance Metrics ------------------------------------------------- [--] Up for: 27m 7s (59K q [36.331 qps], 1K conn, TX: 553M, RX: 10M) [--] Reads / Writes: 88% / 12% [--] Total buffers: 452.0M global + 6.4M per thread (151 max threads) [OK] Maximum possible memory usage: 1.4G (70% of installed RAM) [OK] Slow queries: 0% (0/59K) [OK] Highest usage of available connections: 3% (5/151) [OK] Key buffer size / total MyISAM indexes: 256.0M/70.1M [OK] Key buffer hit rate: 99.3% (1M cached / 8K reads) [OK] Query cache efficiency: 78.8% (41K cached / 52K selects) [OK] Query cache prunes per day: 0 [OK] Sorts requiring temporary tables: 0% (0 temp sorts / 1K sorts) [!!] Joins performed without indexes: 109 [!!] Temporary tables created on disk: 75% (1K on disk / 2K total) [OK] Thread cache hit rate: 99% (5 created / 1K connections) [!!] Table cache hit rate: 2% (256 open / 9K opened) [OK] Open file limit used: 26% (271/1K) [OK] Table locks acquired immediately: 99% (15K immediate / 15K locks) [!!] Connections aborted: 23% [OK] InnoDB buffer pool / data size: 128.0M/82.0M [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 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 Increase table_open_cache gradually to avoid file descriptor limits Read this before increasing table_open_cache over 64: http://bit.ly/1mi7c4C Your applications are not closing MySQL connections properly Variables to adjust: join_buffer_size (> 128.0K, or always use indexes with joins) tmp_table_size (> 16M) max_heap_table_size (> 16M) table_open_cache (> 256) |
Of course you can use
1 |
myqlcheck -A –optimize |
but it will take more time than optimizing the specific tables that are fragmented. In order to do that, you can use this bash script (I originally found it here). Before using any script or modify anything in mysql consider use mysqltuner, it will give you a good overview of your mysql server.