Tuning wydajności MySQL
Uwaga: Prosimy zwrócić uwagę, że ten artykuł / kategoria nie jest już aktualizowana, gdyż odnosi się do starszych komponentów oprogramowania / sprzętu. Ta strona jest nadal dostępna jedynie w celach informacyjnych. |
---|
Ten artykuł opisuje różne sposoby analizy i optymalizacji wydajności serwera MySQL. Przedstawione są zarówno wskazówki z literatury jak i z różnych narzędzi.
Teoria
Szkolenia / certyfikaty MySQL
MySQL oferuje różne szkolenia, które mogą się zakończyć egzaminem i certyfikatem.
Oferowane są między innymi następujące szkolenia:
- MySQL for Database Administrators (CMDBA)
- MySQL for Developers (CMDEV)
- MySQL Cluster Database Administrator (CMCDBA)
- MySQL Performance Tuning
Wszystkie aktualne informacje odnośnie szkoleń znajdują się na: http://www.mysql.com/training
Literatura
- MySQL Performance Blog von Percona [1]
- mySQL DBA Blog [2]
- MySQL Community Librarian [3]
- Książka "High Performance MySQL" autor: O'Reilly (dostępna w języku niemieckim i angielskim)
- Artykuł Pro-Linux [4] (j. niemiecki)
Oprogramowanie monitoringu
- MySQL Enterprise Monitor von MySQL (komercyjny), http://www.mysql.de/products/enterprise/monitor.html (j. niemiecki)
- Kontrollbase, http://kontrollsoft.com/software-kontrollbase
- Nagios Plugins, vide Monitoringexchange i Nagios Exchange
- Cacti Mysql Templates, http://code.google.com/p/mysql-cacti-templates/
Przykład wykresu analizy Mysql Cacti:
Narzędzia
mysqltuner.pl
Ten skrypt Perl umożliwia szybki i prosty przegląd stanu serwera MySQL. W obszarze Recommendations wyniku skryptu zawarte są wskazówki jak dzięki łatwym ulepszeniom konfiguracji może zostać zwiększona wydajność serwera MySQL.
Skrypt może zostać uruchomiony w dwóch etapach.
Wpierw za pośrednictwem wget musi zostać pobrana aktualna wersja:
server:~# wget http://mysqltuner.pl
Alternatywnie w Ubuntu i Debianie mysqltuner może zostać zainstalowany bezpośrednio z repozytorium:
server:~# apt-get install mysqltuner
Następnie MySQL-Tuner zostaje uruchomiony, przy czym konieczne może być podanie danych dostępowych MySQL.
Poniżej przykład wyniku z niezoptymalizowanego serwera MySQL:
server:~# perl mysqltuner.pl >> MySQLTuner 1.0.1 - Major Hayden <major@mhtx.net> >> 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: XXXXXXXX -------- General Statistics -------------------------------------------------- [--] Skipped version check for MySQLTuner script [OK] Currently running supported MySQL version 5.0.51a-24+lenny2+spu1 [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: 1M (Tables: 26) [--] Data in InnoDB tables: 22M (Tables: 39) [--] Data in MEMORY tables: 0B (Tables: 1) [!!] Total fragmented tables: 10 -------- Performance Metrics ------------------------------------------------- [--] Up for: 11d 16h 28m 56s (8M q [8.714 qps], 597K conn, TX: 2B, RX: 1B) [--] Reads / Writes: 93% / 7% [--] Total buffers: 58.0M global + 2.6M per thread (100 max threads) [OK] Maximum possible memory usage: 320.5M (15% of installed RAM) [OK] Slow queries: 0% (0/8M) [OK] Highest usage of available connections: 19% (19/100) [OK] Key buffer size / total MyISAM indexes: 16.0M/1.9M [OK] Key buffer hit rate: 99.4% (266K cached / 1K reads) [OK] Query cache efficiency: 70.2% (4M cached / 6M selects) [!!] Query cache prunes per day: 2132 [OK] Sorts requiring temporary tables: 0% (0 temp sorts / 586K sorts) [!!] Temporary tables created on disk: 30% (24K on disk / 81K total) [OK] Thread cache hit rate: 99% (1K created / 597K connections) [!!] Table cache hit rate: 14% (64 open / 433 opened) [OK] Open file limit used: 0% (6/1K) [OK] Table locks acquired immediately: 100% (2M immediate / 2M locks) [!!] InnoDB data size / buffer pool: 22.1M/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: query_cache_size (> 16M) tmp_table_size (> 32M) max_heap_table_size (> 16M) table_cache (> 64) innodb_buffer_pool_size (>= 22M)