Ottimizzare le performances di MySQL

Da Guide@Debianizzati.Org.
Vai alla navigazione Vai alla ricerca
La versione stampabile non è più supportata e potrebbe contenere errori di resa. Aggiorna i preferiti del tuo browser e usa semmai la funzione ordinaria di stampa del tuo browser.
Debian-swirl.png Versioni Compatibili

Debian 6 "squeeze"
Debian 7 "wheezy"
Debian 8 "jessie"
Debian 9 "stretch"

Ottimizzare le performances di MySQL

MySQLTuner è uno script in Perl che in analizza il server MySQL e suggerisce le impostazioni migliori basandosi sulle sue statistiche di utilizzo.
Non è la strada più completa per ottimizzare il nostro database server, ma è una via rapida e che fornisce sufficienti miglioramenti da giustificare la sua installazione:

# apt-get install mysqltuner

Da adesso, digitando mysqltuner nella nostra shell possiamo lanciare il tool:

# mysqltuner
>> MySQLTuner 0.9.0 - Major Hayden
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
Please enter your MySQL administrative login: root
Please enter your MySQL administrative password:
-------- General Statistics --------------------------------------------------
[!!] There is a new version of MySQLTuner available
[OK] Currently running supported MySQL version 5.0.51a-24+lenny4-log
[OK] Operating on 64-bit architecture
-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 4M (Tables: 1311)
[--] Data in InnoDB tables: 300M (Tables: 2275)
-------- Performance Metrics -------------------------------------------------
[--] Up for: 17h 28m 59s (6M q [97.770 qps], 18K conn, TX: 11B, RX: 1B)
[--] Reads / Writes: 84% / 16%
[--] Total buffers: 2.6M per thread and 106.0M global
[OK] Maximum possible memory usage: 368.5M (9% of installed RAM)
[OK] Slow queries: 0% (2/6M)
[OK] Highest usage of available connections: 11% (11/100)
[OK] Key buffer size / total MyISAM indexes: 16.0M/4.7M
[OK] Key buffer hit rate: 99.2%
[OK] Query cache efficiency: 93.5%
[!!] Query cache prunes per day: 362758
[OK] Sorts requiring temporary tables: 0%
[!!] Joins performed without indexes: 5599
[!!] Temporary tables created on disk: 78%
[OK] Thread cache hit rate: 99%
[!!] Table cache hit rate: 0%
[OK] Open file limit used: 0%
[OK] Table locks acquired immediately: 100%
[!!] InnoDB data size / buffer pool: 300.1M/8.0M
-------- Recommendations -----------------------------------------------------
General recommendations:
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_cache gradually to avoid file descriptor limits
Variables to adjust:
query_cache_size (> 64M)
join_buffer_size (> 128.0K, or always use indexes with joins)
tmp_table_size (> 32M)
max_heap_table_size (> 16M)
table_cache (> 128)
innodb_buffer_pool_size (>= 300M)

L'output de comando è sufficientemente esplicito e fornisce le raccomandazioni sulle modifiche da effettuare in maniera abbastanza chiara. Nel nostro caso MySQLTuner ci dice che vanno aggiunti o modificati i valori delle seguenti variabili:

query_cache_size (> 64M)
join_buffer_size (> 128.0K, or always use indexes with joins)
tmp_table_size (> 32M)
max_heap_table_size (> 16M)
table_cache (> 128)
innodb_buffer_pool_size (>= 300M)

Apriamo quindi il file di configurazione di MySQL, /etc/mysql/my.cnf e modifichiamolo come suggerito.
Quindi riavviamo il servizio MySQL:

/etc/init.d/mysql restart

Sitografia

Basato sulla guida originale presente sul sito: http://http://ideafactory.it/




Guida scritta da: Ferdybassi 20:52, 20 dic 2010 (CET) Swirl-auth20.png Debianized 20%
Estesa da:
Verificata da:

Verificare ed estendere la guida | Cos'è una guida Debianized