MySQL Tunning

MySQL Tunning

При увеличении баз данных может потребоваться тонкая настройка MySQL. Для этого можно воспользоваться следующим:

Утилита mysqltuner

На примере Ubuntu Linux.
Для установки выполните в командной строке:

 apt-get install mysqltuner

Далее запускаем утилиту без параметров:

mysqltuner

Будет запрошен логин и пароль от MySQL:

 >>  MySQLTuner 1.0.1 - 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 --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.5.52-0ubuntu0.12.04.1
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 2M (Tables: 38)
[--] Data in InnoDB tables: 768K (Tables: 9)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[!!] Total fragmented tables: 9

-------- Performance Metrics -------------------------------------------------
[--] Up for: 14d 10h 57m 54s (26M q [21.459 qps], 2M conn, TX: 23B, RX: 1B)
[--] Reads / Writes: 99% / 1%
[--] Total buffers: 192.0M global + 2.7M per thread (151 max threads)
[OK] Maximum possible memory usage: 597.8M (3% of installed RAM)
[OK] Slow queries: 0% (0/26M)
[OK] Highest usage of available connections: 21% (33/151)
[OK] Key buffer size / total MyISAM indexes: 16.0M/194.0K
[OK] Key buffer hit rate: 100.0% (15M cached / 1K reads)
[OK] Query cache efficiency: 91.8% (16M cached / 18M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 1M sorts)
[!!] Joins performed without indexes: 3974
[!!] Temporary tables created on disk: 49% (1M on disk / 2M total)
[OK] Thread cache hit rate: 99% (2K created / 2M connections)
[!!] Table cache hit rate: 2% (47 open / 2K opened)
[OK] Open file limit used: 3% (38/1K)
[OK] Table locks acquired immediately: 100% (2M immediate / 2M locks)
[OK] InnoDB data size / buffer pool: 768.0K/128.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    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:
    join_buffer_size (> 128.0K, or always use indexes with joins)
    tmp_table_size (> 16M)
    max_heap_table_size (> 16M)
    table_cache (> 128)

В разделе Recommendations указаны рекомендации по настройке MySQL сервера.
Внесите изменения в /etc/mysql/my.cnf указанные в разделе Variables to adjust и перечитайте конфиг сервера:

/etc/init.d/mysql reload

Understanding caches and buffers of MySQL, a good explanation about it:
http://www.percona.com/blog/2006/09/29/what-to-tune-in-mysql-server-after-installation/

For a more automatic review of your MySQl server you can use tools that make some advisory about your specific need, a good article summarizing great tools is:
http://www.askapache.com/mysql/performance-tuning-mysql.html

Percona Tools can help you to configure your my.cnf by ask questions:
https://tools.percona.com/wizard
(free, but need registration).

Пример:
The WAF-FLE user Fábio Miranda shared his tuning tip of MySQL, with great improve in response time (from a base about 70GB running on a VM with 6GB RAM):
In /etc/my.cnf :

#tuning
query_cache_size=64M
thread_cache_size=4
table_cache=256
key_buffer_size=1300M

.

Закладка Постоянная ссылка.

Добавить комментарий

Ваш e-mail не будет опубликован.

*