如何减少mysql使用的内存

phi*_*o37 5 mysql

我正在使用 MySQL 5.1 并希望升级到最新版本 5.6.17(来自Windows Installer

但是当我安装时,它使用了太多内存,大约420Mb,虽然5.1版本只运行8Mb内存。我选择的设置类型:

  • 安装类型:仅服务器

  • 配置类型:开发机

我不希望它使用太多内存,我该怎么办,或者使用最小内存的 MySQL 最新版本是什么,例如 5.1

我将配置类型更改为另一种类型,但它仍然使用超过 400Mb 的内存

Mor*_*ker 7

我在这里有一篇文章:http : //www.tocker.ca/configuring-mysql-to-use-minimal-memory.html

MySQL 默认设置必须在性能与被认为是合理的性能之间取得平衡,因为它可能是一个开发系统,其他应用程序需要与 MySQL 一起运行。在许多情况下,这意味着 4-8GB,但在虚拟机上(或者在我的情况下运行 7 个 mysqld 副本),可用空间要少得多。

强制性警告:如果您在具有 1GB 以上 RAM 的机器上运行这些设置,与默认设置相比,您应该期望更差的性能。

Setting                     Default      Minimum
innodb_buffer_pool_size     128M         5M
innodb_log_buffer_size      1M           256K
query_cache_size            1M           0
max_connections             151          1 (although 10 might be more reasonable)
key_buffer_size             8388608      8
thread_cache_size           (autosized)  0
host_cache_size             (autosized)  0
innodb_ft_cache_size        8000000      1600000
innodb_ft_total_cache_size  640000000    32000000
thread_stack    262144      131072
sort_buffer_size            262144       32K
read_buffer_size            131072       8200
read_rnd_buffer_size        262144       8200
max_heap_table_size         16777216     16K
tmp_table_size  16777216    1K
bulk_insert_buffer_size     8388608      0
join_buffer_size            262144       128
net_buffer_length           16384        1K
innodb_sort_buffer_size     1M           64K
binlog_cache_size           32K          4K
binlog_stmt_cache_size      32K          4K
Run Code Online (Sandbox Code Playgroud)

总结这些变化:

# /etc/my.cnf:
innodb_buffer_pool_size=5M
innodb_log_buffer_size=256K
query_cache_size=0
max_connections=10
key_buffer_size=8
thread_cache_size=0
host_cache_size=0
innodb_ft_cache_size=1600000
innodb_ft_total_cache_size=32000000

# per thread or per operation settings
thread_stack=131072
sort_buffer_size=32K
read_buffer_size=8200
read_rnd_buffer_size=8200
max_heap_table_size=16K
tmp_table_size=1K
bulk_insert_buffer_size=0
join_buffer_size=128
net_buffer_length=1K
innodb_sort_buffer_size=64K

#settings that relate to the binary log (if enabled)
binlog_cache_size=4K
binlog_stmt_cache_size=4K
Run Code Online (Sandbox Code Playgroud)


Max*_*eul 3

你能粘贴结果吗

show variables like "%size%";
show variables like "%buffer%";
show variables like "%cache%";
Run Code Online (Sandbox Code Playgroud)

在默认的“配置类型:开发机”中,对于开发服务器来说,有一个参数值得怀疑,那就是table_definition_cache

我确定你的设置为 1400 不是吗?

在您的 my.ini 文件中对其进行注释,或者将其设置为默认值:400。

table_definition_cache 参数是一个动态变量,因此您可以在不重新启动 MySQL 的情况下设置它:

set global table_definition_cache=400;
Run Code Online (Sandbox Code Playgroud)

请注意,如果您没有很多表,则可以将其设置为低于 400。

最大限度。