查看全局内存和session内存使用情况
参考:https://dev.mysql.com/doc/refman/8.0/en/memory-use.html
-- 排除了innodb_additional_mem_pool_size 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 + @@tmp_table_size ) ) / (1024 * 1024 * 1024) AS MAX_MEMORY_GB ,@@innodb_buffer_pool_size / (1024 * 1024 * 1024) as innodb_buffer_pool_size_GB ,@@max_connections as max_connections ,( @@read_buffer_size + @@read_rnd_buffer_size + @@sort_buffer_size + @@join_buffer_size + @@binlog_cache_size + @@thread_stack + @@tmp_table_size ) / (1024 * 1024 ) as session_all_MB ,@@tmp_table_size / (1024 * 1024 ) as tmp_table_size_MB ,@@read_buffer_size / (1024 * 1024 ) as read_buffer_size_MB ,@@read_rnd_buffer_size / (1024 * 1024 ) as read_rnd_buffer_size_MB ,@@sort_buffer_size / (1024 * 1024 ) as sort_buffer_size_MB ,@@join_buffer_size / (1024 * 1024 ) as join_buffer_size_MB ,@@binlog_cache_size / (1024 * 1024 ) as binlog_cache_size_MB ,@@thread_stack /(1024 * 1024 ) as thread_stack_MB \G
结果: *************************** 1. row *************************** MAX_MEMORY_GB: 1511.0586 innodb_buffer_pool_size_GB: 32.0000 max_connections: 20000 session_all_MB: 75.6250 tmp_table_size_MB: 64.0000 read_buffer_size_MB: 1.0000 read_rnd_buffer_size_MB: 2.0000 sort_buffer_size_MB: 8.0000 join_buffer_size_MB: 0.1250 binlog_cache_size_MB: 0.2500 thread_stack_MB: 0.2500 1 row in set (0.00 sec)