【问题标题】:mysql Fatal error: cannot allocate memory for the buffer poolmysql致命错误:无法为缓冲池分配内存
【发布时间】:2014-11-15 22:06:02
【问题描述】:

我有这个来自 MySQL 的错误日志,你知道吗? 网站工作了一段时间,然后我在几个小时后完全关闭了 MySQL。

140919 10:48:27 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
140919 10:48:27 [Note] Plugin 'FEDERATED' is disabled.
140919 10:48:27 InnoDB: The InnoDB memory heap is disabled
140919 10:48:27 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140919 10:48:27 InnoDB: Compressed tables use zlib 1.2.3.4
140919 10:48:28 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
140919 10:48:28 InnoDB: Completed initialization of buffer pool
140919 10:48:28 InnoDB: Fatal error: cannot allocate memory for the buffer pool
140919 10:48:28 [ERROR] Plugin 'InnoDB' init function returned error.
140919 10:48:28 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140919 10:48:28 [ERROR] Unknown/unsupported storage engine: InnoDB
140919 10:48:28 [ERROR] Aborting

140919 10:48:28 [Note] /usr/sbin/mysqld: Shutdown complete

140919 10:48:28 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
140919 10:48:28 [Note] Plugin 'FEDERATED' is disabled.
140919 10:48:28 InnoDB: The InnoDB memory heap is disabled
140919 10:48:28 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140919 10:48:28 InnoDB: Compressed tables use zlib 1.2.3.4
140919 10:48:28 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
140919 10:48:28 InnoDB: Completed initialization of buffer pool
140919 10:48:28 InnoDB: Fatal error: cannot allocate memory for the buffer pool
140919 10:48:28 [ERROR] Plugin 'InnoDB' init function returned error.
140919 10:48:28 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140919 10:48:28 [ERROR] Unknown/unsupported storage engine: InnoDB
140919 10:48:28 [ERROR] Aborting

140919 10:48:28 [Note] /usr/sbin/mysqld: Shutdown complete

【问题讨论】:

  • 我也有同样的问题
  • 我发现我的服务器内存不足。我创建了一些交换空间,它为我解决了这个问题。
  • Stack Overflow 是一个编程和开发问题的网站。这个问题似乎离题了,因为它与编程或开发无关。请参阅帮助中心的What topics can I ask about here。也许Super UserDatabase Administrators Stack Exchange 会是一个更好的提问地点。
  • 显然它对某些人有用

标签: mysql innodb


【解决方案1】:

TLDR;

由于内存不足,Mysql 无法重新启动,请检查您是否配置了适当的交换文件。

没有帮助?如果这不是您的问题,继续研究的更多合格问题是:

背景

我在 EC2 上设置的第一个系统就遇到了这个问题,其特点是托管在那里的 wordpress 站点有时会出现“建立数据库连接时出错”。

日志显示了与 OP 发布的相同的错误。我对错误的阅读(删除了时间戳)是:

  • 内存不足错误: InnoDB: Fatal error: cannot allocate memory for the buffer pool
  • InnoDB 无法在没有足够内存的情况下启动 [ERROR] Plugin 'InnoDB' init function returned error. [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. [ERROR] Unknown/unsupported storage engine: InnoDB [ERROR] Aborting
  • mysqld 正在关闭,在这种情况下,这实际上意味着无法重新启动! [Note] /usr/sbin/mysqld: Shutdown complete

检查 /var/log/syslog 并搜索 mysql 得到:

Out of memory: Kill process 15452 (mysqld) score 93 or sacrifice child
Killed process 15452 (mysqld) total-vm:888672kB, anon-rss:56252kB, file-rss:0kB
init: mysql main process (15452) killed by KILL signal
init: mysql main process ended, respawning
type=1400 audit(1443812767.391:30): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=21984 comm="apparmor_parser"
init: mysql main process (21996) terminated with status 1
init: mysql main process ended, respawning
init: mysql post-start process (21997) terminated with status 1
<repeated>

注意:如果错误发生在 cron 轮换日志之前,您可能需要压缩并搜索归档日志。

解决方案

就我而言,根本问题是我忽略了配置交换文件。

您可以通过运行free -m 来检查您是否配置了一个。

total used free shared buffers cached Mem: 604340 587364 16976 0 29260 72280 -/+ buffers/cache: 485824 118516 Swap: 0 0 0

在上面的例子中,Swap: 0 表示没有交换文件。

设置教程:

注意,越大不一定越好!来自Ubuntu guide

“收益递减”意味着如果您需要的交换空间比 RAM 大小的两倍多,您最好添加更多 RAM,因为硬盘驱动器 (HDD) 的访问速度比 RAM 慢约 10³访问,所以原本需要 1 秒的东西,突然需要超过 15 分钟!在快速固态驱动器 (SSD) 上还要超过一分钟...


关于这里的其他答案...

The InnoDB memory heap is disabled

这并不是真正的错误,只是表明 InnoDB 正在使用系统的内部内存分配器而不是它自己的。默认是yes/1,生产环境可以接受。

根据文档,此命令已弃用,并将在 MySQL 5.6 以上版本中删除(我假设是 MariaDB):

http://dev.mysql.com/doc/refman/5.6/en/innodb-performance-use_sys_malloc.html

感谢:Ruben Schade comment

[Note] Plugin 'FEDERATED' is disabled.

关于 FEDERATED disabled 的消息不是错误。这只是意味着 FEDERATED 引擎对于您的 mysql 服务器没有开启。默认情况下不使用它。如果您不需要它,请不要关心此消息。

见:https://stackoverflow.com/a/16470822/2586761

【讨论】:

  • 我有类似的问题,但有点不同,mysql可以正常启动,但是关闭一段时间后我得到这个错误。
  • @ptim。你真的拯救了我的一天。数字海洋教程帮助很大。我在 512mb 液滴中遇到了问题
  • 刚刚出现同样的错误,但配置了交换文件!
  • 你刚刚拯救了我一整天。非常感谢。
  • 放置交换文件解决了我的问题。
【解决方案2】:

解决方案不是更多空间,问题是 Apache web server 不是 mysql,实际上你需要减少 innodb-buffer-pool-size

mysql 进程一开始就使用这个缓冲区,所以当 Apache 需要更多资源时,内核会从服务中清除 RAM,这意味着停止 mysql 而不是让服务器崩溃。

如果您不想更改为 ngnx 或 httplight,还可以添加一个 CRON 来检查数据库状态并重新启动它。

【讨论】:

  • 我在 Digital Ocean 1GB ram 服务器上遇到了与 WordPress 类似的问题。我注意到free 命令显示大约一半的内存仍然可用,所以我将添加交换并尝试此解决方案。但是,减少 innodb_buffer_pool_size 会导致 mysql/mariadb 的任何性能损失
【解决方案3】:

我发现这个答案增加了讨论:https://www.digitalocean.com/community/questions/mysql-server-keeps-stopping-unexpectedly?answer=26021

简而言之,除了将 innodb_buffer_pool_size 设置为 64M 等合理值之外,您还可能需要修改 /etc/apache2/mods-enabled/mpm_prefork.conf 以减少 apache 启动的连接数;

<IfModule mpm_prefork_module>
    StartServers     3
    MinSpareServers  3
    MaxSpareServers  5
    MaxRequestWorkers 25
    MaxConnectionsPerChild   1024
</IfModule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    相关资源
    最近更新 更多