In the past few weeks we’ve been looking into different MySQL configuration options and were running many simple tests. Even though all tests were different and were targeting different configuration options – one thing was common – there were no simultaneous connections and queries to the same tables.
Configuration options, that made huge difference, comparing to the default values
- Query cache must be enabled and configured
1 2 3 4 |
query_cache_type=1 query_cache_limit=1M query_cache_size=256M query_cache_min_res_unit=512 |
2. Various read and sort buffers must be set
1 2 3 4 5 6 |
key_buffer_size=128M join_buffer_size=8M myisam_sort_buffer_size=1M sort_buffer_size=1M read_buffer_size=4M read_rnd_buffer_size=4M |
3. Set InnoDB tables to be stored each in separate file
1 |
innodb_file_per_table=1 |
4. Tweak MyISAM table
1 |
myisam_use_mmap=1 |
Configuration options, that help to run more complex queries
- Let MySQL have larger in-memory temporary tables
1 2 |
tmp_table_size=256M max_heap_table_size=256M |
2. Tweak InnoDB engine
1 2 3 4 5 |
innodb_buffer_pool_size=134217728 innodb_flush_log_at_trx_commit=2 innodb_thread_concurrency=8 innodb_use_sys_malloc=1 innodb_buffer_pool_size=128M |
3. Additional tweaks – open file limit, skip name resolve, maximum size of a single packet, number of opened tables to keep in memory
1 2 3 4 |
open_files_limit=50000 skip-name-resolve table_open_cache=4096 table_definition_cache=4096 |
Combined my.cnf, ready to be copied and deployed
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 |
[mysqld] query_cache_type=1 query_cache_limit=1M query_cache_size=256M query_cache_min_res_unit=512 key_buffer_size=128M join_buffer_size=8M myisam_sort_buffer_size=1M sort_buffer_size=1M read_buffer_size=4M read_rnd_buffer_size=4M innodb_file_per_table=1 myisam_use_mmap=1 tmp_table_size=256M max_heap_table_size=256M innodb_buffer_pool_size=134217728 innodb_flush_log_at_trx_commit=2 innodb_thread_concurrency=8 innodb_use_sys_malloc=1 innodb_buffer_pool_size=128M open_files_limit=50000 skip-name-resolve table_open_cache=4096 table_definition_cache=4096 |