Skip to content

Instantly share code, notes, and snippets.

@v0112358
Last active December 30, 2023 13:34
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save v0112358/8ab917ac7af92609b9f566fa42c579be to your computer and use it in GitHub Desktop.
Save v0112358/8ab917ac7af92609b9f566fa42c579be to your computer and use it in GitHub Desktop.
MySQL Memory Calculator

MySQL 5.6

Base memory

SELECT ( @@key_buffer_size
+ @@query_cache_size
+ @@innodb_buffer_pool_size
+ @@innodb_log_buffer_size
+ @@innodb_additional_mem_pool_size )
/ (1024 * 1024 * 1024) AS BASE_MEMORY_GB;

Max memory

SELECT ( @@key_buffer_size
+ @@query_cache_size
+ @@innodb_buffer_pool_size
+ @@innodb_log_buffer_size
+ @@innodb_additional_mem_pool_size
+ @@max_connections * ( 
    @@read_buffer_size
    + @@read_rnd_buffer_size
    + @@sort_buffer_size
    + @@join_buffer_size
    + @@binlog_cache_size
    + @@thread_stack
    + @@max_heap_table_size )
) / (1024 * 1024 * 1024) AS MAX_MEMORY_GB;

MySQL 5.7

Base memory

SELECT ( @@key_buffer_size
+ @@query_cache_size
+ @@innodb_buffer_pool_size
+ @@innodb_log_buffer_size )
/ (1024 * 1024 * 1024) AS BASE_MEMORY_GB;

Max memory

SELECT ( @@key_buffer_size
+ @@query_cache_size
+ @@innodb_buffer_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
    + @@max_heap_table_size )
) / (1024 * 1024 * 1024) AS MAX_MEMORY_GB;

MySQL 8.x

Base memory

SELECT ( @@key_buffer_size
+ @@query_cache_size
+ @@innodb_buffer_pool_size
+ @@innodb_log_buffer_size )
/ (1024 * 1024 * 1024) AS BASE_MEMORY_GB;

Max memory

SELECT ( @@key_buffer_size
+ @@innodb_buffer_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
    + @@max_heap_table_size )
) / (1024 * 1024 * 1024) AS MAX_MEMORY_GB;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment