MySQL8.0内存分配
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
root@db 17:15: [(none)]> select ( @@key_buffer_size + @@innodb_buffer_pool_size + @@innodb_log_buffer_size + @@binlog_cache_size+ @@max_connections
-> *( @@read_buffer_size + @@read_rnd_buffer_size + @@sort_buffer_size +
-> @@join_buffer_size + @@thread_stack + @@tmp_table_size ) ) / (1024 * 1024 * 1024) as max_memory_gb;
+---------------+
| max_memory_gb |
+---------------+
| 21.4951 |
+---------------+
1 row in set (0.00 sec)
在实际工作中,这里算出来的数值通常偏大,因为所有的线程都同时用到设定内存分配的最大值的情况几乎不会出现,每个线程如果只是处理简单的工作,大约只需要 256KB 的内存。通过查询 sys.memory_global_total 视图可以得到当前 MySQL 实例使用内存总和。
root@db 17:15: [(none)]> select * from sys.memory_global_total;
+-----------------+
| total_allocated |
+-----------------+
| 4.38 GiB |
+-----------------+
1 row in set (0.00 sec)