12月21, 2022
收藏本站

MySQL内存计算

1. 最大可使用内存( M ):

SELECT 
  (
    @@key_buffer_size + 
    @@query_cache_size + 
    @@tmp_table_size + 
    @@innodb_buffer_pool_size  + 
    @@innodb_log_buffer_size + 
    @@max_connections * (
        @@sort_buffer_size + 
        @@read_buffer_size + 
        @@read_rnd_buffer_size + 
        @@join_buffer_size + 
        @@binlog_cache_size + 
        @@thread_stack
    )
  ) / 1024 / 1024  as `MaxMem(M)` ;

2.单个连接最大可使用内存( M ):

  SELECT 
 (
     @@sort_buffer_size + 
     @@read_buffer_size + 
     @@read_rnd_buffer_size + 
     @@join_buffer_size + 
     @@binlog_cache_size + 
     @@thread_stack
 ) / 1024 / 1024 AS `ConnectMem(M)` ;

3.最大可使用内存(不包含连接占用内存)( M ):

   SELECT 
     (
   @@key_buffer_size + 
   @@query_cache_size + 
   @@tmp_table_size + 
   @@innodb_buffer_pool_size  + 
   @@innodb_log_buffer_size
     ) / 1024 / 1024 AS `MaxMemExcCon(M)`;

Comments