{"id":3842,"date":"2018-01-29T21:51:50","date_gmt":"2018-01-29T21:51:50","guid":{"rendered":"https:\/\/qbytes.cloud\/?p=3842"},"modified":"2018-01-29T21:51:50","modified_gmt":"2018-01-29T21:51:50","slug":"calculate-mysql-max_connections-variable","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2018\/01\/29\/calculate-mysql-max_connections-variable\/","title":{"rendered":"How do you calculate mysql max_connections variable"},"content":{"rendered":"<p>The basic formulas are:<\/p>\n<p>Available RAM = Global Buffers + (Thread Buffers x max_connections)<br \/>\nmax_connections = (Available RAM &#8211; Global Buffers) \/ Thread Buffers<\/p>\n<p>To get the list of buffers and their values:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\nSHOW VARIABLES LIKE &#039;%buffer%&#039;;\n\n<\/pre>\n<p>Here&#8217;s a list of the buffers and whether they&#8217;re Global or Thread:<\/p>\n<p>Global Buffers: key_buffer_size, innodb_buffer_pool_size, innodb_log_buffer_size, innodb_additional_mem_pool_size, net_buffer_size, query_cache_size<br \/>\nThread Buffers: sort_buffer_size, myisam_sort_buffer_size, read_buffer_size, join_buffer_size, read_rnd_buffer_size, thread_stack<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nMariaDB &#x5B;(none)]&gt; SHOW VARIABLES LIKE &#039;%buffer%&#039;;\n+---------------------------------------+-----------+\n| Variable_name                         | Value     |\n+---------------------------------------+-----------+\n| aria_pagecache_buffer_size            | 134217728 |\n| aria_sort_buffer_size                 | 134217728 |\n| bulk_insert_buffer_size               | 8388608   |\n| innodb_blocking_buffer_pool_restore   | OFF       |\n| innodb_buffer_pool_instances          | 1         |\n| innodb_buffer_pool_populate           | OFF       |\n| innodb_buffer_pool_restore_at_startup | 0         |\n| innodb_buffer_pool_shm_checksum       | ON        |\n| innodb_buffer_pool_shm_key            | 0         |\n| innodb_buffer_pool_size               | 134217728 |\n| innodb_change_buffering               | all       |\n| innodb_log_buffer_size                | 8388608   |\n| join_buffer_size                      | 131072    |\n| join_buffer_space_limit               | 2097152   |\n| key_buffer_size                       | 16777216  |\n| mrr_buffer_size                       | 262144    |\n| myisam_sort_buffer_size               | 8388608   |\n| net_buffer_length                     | 8192      |\n| preload_buffer_size                   | 32768     |\n| read_buffer_size                      | 262144    |\n| read_rnd_buffer_size                  | 524288    |\n| sort_buffer_size                      | 524288    |\n| sql_buffer_result                     | OFF       |\n+---------------------------------------+-----------+\n\n<\/pre>\n<p>Lets find out the RAM:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# free -b\n              total        used        free      shared  buff\/cache   available\nMem:     3975184384   978608128  1691045888     9445376  1305530368  2661937152\n\n<\/pre>\n<p>Lets get our data together.<\/p>\n<p>RAM = 3975184384<br \/>\nGlobal Buffers: key_buffer_size, innodb_buffer_pool_size, innodb_log_buffer_size, innodb_additional_mem_pool_size, net_buffer_length, query_cache_size<br \/>\nor, from above&#8230;<br \/>\nGlobal Buffers: 16777216 + 134217728 + 8388608 + 0 + 8192 + 0 = 159391744<\/p>\n<p>Thread Buffers: sort_buffer_size, myisam_sort_buffer_size, read_buffer_size, join_buffer_size, read_rnd_buffer_size, thread_stack<br \/>\nor, from above&#8230;<br \/>\nThread Buffers: 524288 + 8388608 + 262144 + 131072 + 524288 + 0 = 9830400<\/p>\n<p>With this information, the following is the calculation:<br \/>\nmax_connections = (Available RAM &#8211; Global Buffers) \/ Thread Buffers<br \/>\nmax_connections = (3975184384 &#8211; 159391744) \/ 9830400<\/p>\n<p>So the formula shows 378 Max Connections on this machine<\/p>\n<p>Test info with mysqltuner<\/p>\n<p>Log into your server with a root or sudo user via SSH.<br \/>\nDownload MySQLTuner by executing the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\nwget -O mysqltuner.pl https:\/\/raw.githubusercontent.com\/major\/MySQLTuner-perl\/master\/mysqltuner.pl --no-check-certificate\n\n<\/pre>\n<p>Give the script 775 permissions:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\nchmod 775 mysqltuner.pl\n\n<\/pre>\n<p>Run the script with the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\nperl mysqltuner.pl\n\n<\/pre>\n<p>Resources:<br \/>\nHandy Calculator Download:  https:\/\/journeyontux.wordpress.com\/2011\/12\/22\/calculate-number-of-connections-for-mysql-server\/<br \/>\nAnother Calculator: http:\/\/www.mysqlcalculator.com\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The basic formulas are: Available RAM = Global Buffers + (Thread Buffers x max_connections) max_connections = (Available RAM &#8211; Global Buffers) \/ Thread Buffers To get the list of buffers and their values: SHOW VARIABLES LIKE &#039;%buffer%&#039;; Here&#8217;s a list of the buffers and whether they&#8217;re Global or Thread: Global Buffers: key_buffer_size, innodb_buffer_pool_size, innodb_log_buffer_size, innodb_additional_mem_pool_size, &#8230; <a title=\"How do you calculate mysql max_connections variable\" class=\"read-more\" href=\"https:\/\/www.qbytes.cloud\/index.php\/2018\/01\/29\/calculate-mysql-max_connections-variable\/\" aria-label=\"Read more about How do you calculate mysql max_connections variable\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,70],"tags":[],"class_list":["post-3842","post","type-post","status-publish","format-standard","hentry","category-administration","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/3842","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=3842"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/3842\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=3842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=3842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=3842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}