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. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do you calculate mysql max_connections ?

What do you take into consideration ?

share|improve this question
Good question, and I wanted to know the answer as well. Reading through this older blog about it:… – Derek Downey Feb 15 '11 at 14:31
up vote 13 down vote accepted

Going to post this as an answer, with the relevant information. The basic formulas are:

Available RAM = Global Buffers + (Thread Buffers x max_connections)

max_connections = (Available RAM - Global Buffers) / Thread Buffers

To get the list of buffers and their values:


Here's a list of the buffers and whether they're Global or Thread:

Global Buffers: key_buffer_size, innodb_buffer_pool_size, innodb_log_buffer_size, innodb_additional_mem_pool_size, net_buffer_size, query_cache_size

Thread Buffers: sort_buffer_size, myisam_sort_buffer_size, read_buffer_size, join_buffer_size, read_rnd_buffer_size, thread_stack

share|improve this answer
KCD provided this link as a max memory calculator: – Derek Downey Apr 26 '13 at 13:15

Here's another alternative formula in sproc form:

CREATE PROCEDURE sproc_show_max_memory ( OUT max_memory DECIMAL(7,4))
SELECT ( @@key_buffer_size + @@query_cache_size + @@tmp_table_size + @@innodb_buffer_pool_size + @@innodb_additional_mem_pool_size + @@innodb_log_buffer_size + @@max_connections * ( @@read_buffer_size + @@read_rnd_buffer_size + @@sort_buffer_size + @@join_buffer_size + @@binlog_cache_size + @@thread_stack ) ) / 1073741824 AS MAX_MEMORY_GB INTO max_memory;
CALL sproc_show_max_memory(@show_max_memory);
SELECT @show_max_memory;

I’m assuming your using a MySQL database > version 5.1.x and you’re a privileged user. But you play with the max connections by inserting whatever number you want and see the results.

share|improve this answer
I just read your formula. Pretty slick !!! BTW +1 !!! – RolandoMySQLDBA Jul 20 '11 at 20:43
It's probably time to revisit this formula given all the changes in 5.5 and 5.6, but it's still kind of handy. – randy melder Aug 9 '12 at 15:28

I'm staring with number I'm getting from simple calulation: expected_number_of_requests_per_second * expected_average_request_processing_time * 2.

For later tuning, I'm always using monitoring system with historical data and trying to have 20% reserved in case of some peak. It's a bit more complex when you are using some connections pooling (which is usually a good idea) - then you need to monitor number of used connections in pool.

share|improve this answer

Your Answer


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.