Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

May the following my.cnf file be fine for a dedicated server with 64GB of RAM (on Debian)?

I'm running just one website on the server and on high load data insert in some table takes centuries...it seems that the DB can't handle some table lock (50Mb tables, not so much).

If it is fine, then i'll step to analyze every single query.

Any help would be truly appreciated!

[client]

port            = 3306
socket          = /var/run/mysqld/mysqld.sock

[mysqld]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

back_log = 50

skip-networking

max_connections = 100

max_connect_errors = 10

table_open_cache = 4096

table-definition-cache = 4096

skip-external-locking

skip-name-resolve

max_allowed_packet = 32M

binlog_cache_size = 2M

max_heap_table_size = 64M

read_buffer_size = 4M

read_rnd_buffer_size = 32M

sort_buffer_size = 16M

join_buffer_size = 8M

thread_cache_size = 20

thread_concurrency = 16

query_cache_type=1

query_cache_size = 1024M

query_cache_limit = 2M

ft_min_word_len = 4

default-storage-engine = MYISAM

thread_stack = 192K

transaction_isolation = REPEATABLE-READ

tmp_table_size = 4G

log-bin=mysql-bin

binlog_format=mixed

slow_query_log

long_query_time = 2

server-id = 1

key_buffer_size = 16G

bulk_insert_buffer_size = 256M

myisam_sort_buffer_size = 246M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

myisam_recover

innodb_additional_mem_pool_size = 16M

innodb_buffer_pool_size = 12G

innodb_data_file_path = ibdata1:10M:autoextend

innodb_file_io_threads = 4

innodb_thread_concurrency = 16

innodb_flush_log_at_trx_commit = 1

innodb_log_buffer_size = 8M

innodb_log_file_size = 256M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

max_allowed_packet = 16M

[mysql]

no-auto-rehash

[myisamchk]

key_buffer_size = 512M

sort_buffer_size = 512M

read_buffer = 8M

write_buffer = 8M

[mysqlhotcopy]

interactive-timeout

[mysqld_safe]

open-files-limit = 8192
share|improve this question

2 Answers 2

A good tool to help you tune MySQL config is the Percona Configuration Wizard for MySQL. This asks you some questions about your system and your workload, and gives you some approximate tuning values to start with.

Of course the term tuning suggests that further refinement may be beneficial, but this happens over time as you monitor your workload, resources usage, and bottlenecks. It's not something we can answer once and for all in a post like this one.

However, I have other comments about your config:

max_allowed_packet = 32M

This is not going to take effect, because you override it with a smaller value later in your config file. See below.

binlog_cache_size = 2M

This is 64x the default. Unless you have a good reason to increase it, don't. Note that the binlog cache is allocated per user thread, so if you have 100 concurrent transactions, this would use 200MB of RAM. Suggest you remove this line and use the default.

max_heap_table_size = 64M

This constrains tmp_table-size. See below.

read_buffer_size = 4M

This is 32x higher than the default. It's used only during table-scans of MyISAM tales. It would be better to create appropriate indexes and avoid table-scans. Suggest you remove this line and use the default.

read_rnd_buffer_size = 32M

This is 128x higher than the default, and 16x higher than the maximum allowed value of 2M. This is used only for MyISAM reads in MySQL 5.5 and earlier, and in MySQL 5.6 it's also used for multi-range reads. But it's probably not necessary to increase it. Suggest you remove this line and use the default.

sort_buffer_size = 16M

This is 4x higher than the default. In MySQL 5.6, it's 16x higher than the default. This is also a buffer that is allocated for each user thread, so be careful how much you increase it. Suggest you remove this line and use the default.

join_buffer_size = 8M

This is 64x higher than the default, so be sure you have a good reason for increasing it. It's used during index scans and joins on unindexed columns. It would be better to index tables better. Keep in mind that the join buffer can be allocated for each user thread, so this 8MB amount can account for unpredictable memory growth. Suggest you remove this line and use the default.

thread_cache_size = 20

Modern Linux kernels can create threads a lot faster than in the old days, so it's no longer as important to keep a thread cache. Suggest you remove this line and use the default.

thread_concurrency = 16

Are you running on Solaris? If not, this variable has no purpose. Suggest you remove this line.

query_cache_type=1
query_cache_size = 1024M

This is a lot of RAM to dedicate to the query cache, and it's probably overallocated. The query cache has some downsides, especially when you have many concurrent connections. Frequently we actually recommend to disable the query cache unless you can demonstrate you're getting a lot of bang for the buck.

Disable by setting both query_cache_type=0 and query_cache_size=0.

ft_min_word_len = 4

This is the default. Suggest you remove this line and use the default.

default-storage-engine = MYISAM

Recommend to set the default storage engine to InnoDB.

I recommend against using MyISAM for anything. MyISAM supports table-locking only, it's susceptible to corruption in crashes, it's not being developed anymore, and it's gradually being phased out. Claims that MyISAM is faster than InnoDB are based on very old versions of MySQL. Even as far back as 2007, benchmarks show that InnoDB is faster than MyISAM under most workloads.

One of the last reasons to use MyISAM, fulltext indexes, is also obsolete. InnoDB is getting fulltext indexes (they were introduced in 5.6, but they're not really usable yet). Sphinx Search is better for fulltext search anyway.

thread_stack = 192K

This is actually lower than the default of 256K on 64-bit systems. Suggest you remove this line and use the default.

transaction_isolation = REPEATABLE-READ

This is the default. Suggest you remove this line and use the default.

tmp_table_size = 4G

This is not going to allow any tmp tables higher than max_heap_table_size, which you set to 32M earlier. So if you want large tmp tables, you must also increase that config variable to match. But be careful, because you could end up with multiple threads populating 4G tmp tables in memory, and then start swapping.

key_buffer_size = 16G
bulk_insert_buffer_size = 256M
myisam_sort_buffer_size = 246M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover

These are used only by MyISAM, and you don't need them if you don't use MyISAM.

innodb_additional_mem_pool_size = 16M

This is moot on modern Linux kernels, where dynamic memory allocation is actually more efficient than letting InnoDB preallocate memory. Suggest you remove this line and use the default.

innodb_buffer_pool_size = 12G

This should be enough to hold all your InnoDB data and indexes, if possible, plus maybe about 10% extra for the change buffer.

You can query the size of your InnoDB data and indexes:

SELECT SUM(data_length+index_length)/1024/1024 AS total_InnoDB_size_in_MB
FROM INFORMATION_SCHEMA.TABLES
WHERE engine = 'InnoDB';

If that total greater than the size of your physical system RAM (64G), then increase the buffer pool as much as is practical. Usually the advice is about 80% of your system RAM, assuming you don't have any other big consumers of memory on the same server. If you do, subtract the memory needed for other processes.

If your data is a lot smaller than your system RAM, then there's no benefit to allocating a big buffer pool. Only one copy of each page of data and indexes is held in the buffer pool.

innodb_data_file_path = ibdata1:10M:autoextend

This is the default.

innodb_file_io_threads = 4

This variable is not recognized after MySQL 5.0 (or 5.1 unless you enable the InnoDB plugin). Use innodb_read_io_threads and innodb_write_io_threads. Besides, you're setting the variable to the default value anyway, so you don't need this line in your config file.

If you're still running a version of MySQL old enough that this variable is recognized, I strongly suggest you upgrade.

innodb_thread_concurrency = 16

This is probably outdated, unless you're running a very old version of MySQL. Suggest you remove this line and use the default of 0 (unlimited thread concurrency) unless you observe a bottleneck.

innodb_flush_log_at_trx_commit = 1

This is the default. Suggest you remove this line and use the default.

innodb_log_buffer_size = 8M

This is the default. Suggest you remove this line and use the default.

innodb_log_file_size = 256M

Is this enough? Too much? Here's a blog to help: http://www.mysqlperformanceblog.com/2008/11/21/how-to-calculate-a-good-innodb-log-file-size/

innodb_log_files_in_group = 3

There's no benefit to changing the innodb log file in group. Suggest you remove this line and use the default.

innodb_max_dirty_pages_pct = 90

This was the default in MySQL 5.0. Now the default is 75. But it's not likely you'll have so many dirty pages regardless. Suggest you remove this line and use the default.

innodb_lock_wait_timeout = 120

The default is 50 (seconds), and should be adequate for most workloads. Do you have a reason to increase this to 120?

max_allowed_packet = 16M

You set max_allowed_packet to 32M earlier. Keep in mind that if you set a given variable in the config file more than once, the last setting takes precedence. So your packets are limited to 16M. If you intend them to be allowed up to 32M, then take out this line.

[myisamchk]

[mysqlhotcopy]

myisamchk and mysqlhotcopy are only used for MyISAM and ARCHIVE tables. If you migrate to use InnoDB, you won't need to use these tools.

share|improve this answer

You can set your MySQL server as:

InnoDB buffer pool= 52G

InnoDB log files =512M

innodb_flush_method= o_direct

Thread cache = 50

Key_buffer = 32M # If you are using MyISAM tables

Max_Connections = 500

Try after setting this value in my.cnf, restart MySQL server and observe it's performance

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.