nk23x
11/18/2015 - 8:42 PM

Optimized MySQL configuration

Optimized MySQL configuration

# The settings provided below are ideal for a 4GB-8GB RAM server.
# You can adjust values accordingly for higher or lower spec systems, but generally,
# it's an almost "one size, fits all" setup.
# Use DB diagnostics tools like:
# https://launchpad.net/mysql-tuning-primer or http://blog.mysqltuner.com/download/
# to get more insight on your MySQL DB's resource usage and more...
# Special thanks to Yves Trudeau (Percona) for his valuable help on compiling this setup.

[mysqld]
default_storage_engine=InnoDB # Options are MyISAM & InnoDB. Prefer the latter

query_cache_limit=2M
query_cache_size=64M
query_cache_type=1

# Connections: If we want 100 connections spawned across 1 user only (max_user_connections),
# leave 20-50 more for system processes.
# If user connections were 200 and we had 2 users,
# the max_connections value would be something between 220-250.
# Increasing the connections does not guarantee better performance, but it DOES guarantee additional memory usage.
max_connections=120
max_user_connections=100

wait_timeout=300 # Time in seconds to keep active connections. The default is 28800 which hogs the connection limits on high traffic sites. 300 is a reasonable value especially on split web/db server setups.

# Key buffers: Sufficient at 64M for most cases,
# increase if mysql-tuning-primer tells you to
key_buffer=64M # Deprecated in MySQL 5.6
key_buffer_size=64M # Replaces "key_buffer" for newer MySQL versions

join_buffer_size=1M
sort_buffer_size=1M
read_buffer_size=1M
read_rnd_buffer_size=1M

max_heap_table_size=128M
tmp_table_size=128M

table_cache=500 # Default is 64, but it's too low - for MySQL 5.6, use "table_open_cache"
table_definition_cache=500 # Should be the same as table_cache
open_files_limit=1500 # Should be set to at least 2x-3x that of table_cache if you have heavy MyISAM usage (default is 4250, which is high enough)

# InnoDB Settings
innodb_buffer_pool_size=1G # Use up to 70-80% of RAM. Also check if /proc/sys/vm/swappiness is set to 0
innodb_file_per_table=1
innodb_flush_log_at_trx_commit=0
innodb_flush_method=O_DIRECT
innodb_log_buffer_size=8M
innodb_log_file_size=128M

# The minimum length of words to be indexed - Commented by default
# Uncomment below to enable searching for three-character words
ft_min_word_len=3

# For MySQL 5.5 or older
log-slow-queries=/var/log/mysql/slow.log
long_query_time=3
#log-queries-not-using-indexes

# For MySQL 5.6
#long_query_time=3
#slow_query_log=1
#slow_query_log_file=/var/log/mysql/slow.log

# === Regarding the MySQL log file location ===
# On Ubuntu servers, do this:
# $ cd /var/log/mysql/; sudo touch slow.log; sudo chmod 0640 slow.log; sudo chown mysql:adm slow.log
# otherwise MySQL may not be able to load the slow.log file

# Advanced
low_priority_updates=1
concurrent_insert=2
thread_cache_size=20 # More here: http://hashmysql.org/index.php?title=Tuning_System_Variables
thread_concurrency=8 # set to 2X the number of processors in your machine for best performance