Hostdog - mysql optimization https://www.hostdog.eu/tags/mysql-optimization en Optimizing MySQL database using mysqltuner.pl https://www.hostdog.eu/blog/optimizing-mysql-database-using-mysqltunerpl <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even">MySQLTuner is a script written in perl which based to MySQL logs, it generates some pretty safe suggestions about which variables can be changed in MySQL config file for a little extra performance First, we download the script and make it executable: <div class="codeblock"><code>wget https://raw.github.com/major/MySQLTuner-perl/master/mysqltuner.pl<br />chmod +x mysqltuner.pl </code></div> Then we run it: <div class="codeblock"><code> ./mysqltuner.pl</code></div> It is for best, that MySQL has not little uptime when running the script, the longer the more accurate suggestions it will be able to output. As opposed to the "MySQL started within last 24 hours – recommendations may be inaccurate." error message if you attempt to run the script right after a MySQL restart. <div class="codeblock"><code> &gt;&gt;  MySQLTuner 1.2.0 - Major Hayden &lt;major@mhtx.net&gt;<br /> &gt;&gt;  Bug reports, feature requests, and downloads at http://mysqltuner.com/<br /> &gt;&gt;  Run with '--help' for additional options and output filtering<br /><br />-------- General Statistics --------------------------------------------------<br />[--] Skipped version check for MySQLTuner script<br />[OK] Currently running supported MySQL version 5.1.68-cll<br />[OK] Operating on 64-bit architecture<br /><br />-------- Storage Engine Statistics -------------------------------------------<br />[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster<br />[--] Data in MyISAM tables: 1G (Tables: 5367)<br />[--] Data in InnoDB tables: 400M (Tables: 4079)<br />[--] Data in MEMORY tables: 0B (Tables: 33)<br />[!!] Total fragmented tables: 4684<br /><br />-------- Security Recommendations  -------------------------------------------<br />[OK] All database users have passwords assigned<br /><br />-------- Performance Metrics -------------------------------------------------<br />[--] Up for: 15d 10h 40m 6s (68M q [51.568 qps], 1M conn, TX: 794B, RX: 12B)<br />[--] Reads / Writes: 77% / 23%<br />[--] Total buffers: 78.0M global + 7.5M per thread (800 max threads)<br />[OK] Maximum possible memory usage: 5.9G (76% of installed RAM)<br />[OK] Slow queries: 0% (1K/68M)<br />[OK] Highest usage of available connections: 8% (66/800)<br />[OK] Key buffer size / total MyISAM indexes: 36.0M/229.4M<br />[OK] Key buffer hit rate: 98.5% (572M cached / 8M reads)<br />[OK] Query cache efficiency: 70.8% (38M cached / 54M selects)<br />[!!] Query cache prunes per day: 723587<br />[OK] Sorts requiring temporary tables: 0% (4K temp sorts / 2M sorts)<br />[!!] Joins performed without indexes: 109545<br />[!!] Temporary tables created on disk: 31% (1M on disk / 4M total)<br />[OK] Thread cache hit rate: 99% (66 created / 1M connections)<br />[!!] Table cache hit rate: 0% (1K open / 83M opened)<br />[OK] Open file limit used: 3% (1K/48K)<br />[OK] Table locks acquired immediately: 99% (26M immediate / 26M locks)<br />[!!] InnoDB data size / buffer pool: 400.4M/8.0M<br /><br />-------- Recommendations -----------------------------------------------------<br />General recommendations:<br />    Run OPTIMIZE TABLE to defragment tables for better performance<br />    Enable the slow query log to troubleshoot bad queries<br />    Adjust your join queries to always utilize indexes<br />    When making adjustments, make tmp_table_size/max_heap_table_size equal<br />    Reduce your SELECT DISTINCT queries without LIMIT clauses<br />    Increase table_cache gradually to avoid file descriptor limits<br />Variables to adjust:<br />    query_cache_size (&gt; 16M)<br />    join_buffer_size (&gt; 2.0M, or always use indexes with joins)<br />    tmp_table_size (&gt; 16M)<br />    max_heap_table_size (&gt; 16M)<br />    table_cache (&gt; 1024)<br />    innodb_buffer_pool_size (&gt;= 400M)</code></div> You should carefully read the results, especially the recommendations at the end which shows exactly which variables you should adjust in the [mysqld] section of your my.cnf file (/etc/mysql/my.cnf for Debian and Ubuntu). Whenever you change your my.cnf, make sure that you restart MySQL service. After changes to my.cnf file, you can come back after 2 or 3 days and run mysqltuner.pl again, in order to see if there are any additional suggestions to improve the MySQL performance. This way you are able to optimize your MySQL's settings step by step. Give extra attention to "Query cache efficiency" percentage and note down it's change. This method is ideal for learning as well, while you may come up with random configurations across the Internet matching your server's specification, they could become confusing when you have to change a bunch of variables at once or it wouldn't give you the time to study how every variable change affects your MySQL server performance. Please note: We hold no responsibility for any changes you make to your my.cnf config file. Also we strongly suggest you to take backups not only from my.cnf config file itself but take whole database backups as well.</div></div></div><div class="field field-name-field-tags field-type-taxonomy-term-reference field-label-above clearfix"><h3 class="field-label">Tags: </h3><ul class="links"><li class="taxonomy-term-reference-0"><a href="https://www.hostdog.eu/tags/linux">linux</a></li><li class="taxonomy-term-reference-1"><a href="https://www.hostdog.eu/tags/mysql">mysql</a></li><li class="taxonomy-term-reference-2"><a href="https://www.hostdog.eu/tags/mysql-optimization">mysql optimization</a></li><li class="taxonomy-term-reference-3"><a href="https://www.hostdog.eu/tags/optimization">optimization</a></li><li class="taxonomy-term-reference-4"><a href="https://www.hostdog.eu/tags/database-optimization">database optimization</a></li><li class="taxonomy-term-reference-5"><a href="https://www.hostdog.eu/tags/mysqltuner">mysqltuner</a></li></ul></div> Wed, 01 May 2013 12:28:53 +0000 ploupas 352 at https://www.hostdog.eu