Mysql自动宕机:InnoDB: Cannot allocate memory for the buffer pool

Posted rocly

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql自动宕机:InnoDB: Cannot allocate memory for the buffer pool相关的知识,希望对你有一定的参考价值。

今天早上上班,发现自己使用wordpress搭建的网站不能访问,报如下错误:

Error establishing a database connection

 

赶紧登到自己阿里云服务器(centos7.4)查看mysql服务,通过ps -ef | grep mysql 发现已经没有了mysql进程。

 

首先要做的是查看mysql日志,通过vi /var/log/mysqld.log果然发现对应的错误异常:

2018-12-26T02:06:16.148626Z 0 [Note] Event Scheduler: Purging the queue. 0 events
"/var/log/mysqld.log" 623L, 59293C
2019-02-01T07:56:07.052989Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2019-02-01T07:56:07.052991Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-02-01T07:56:07.052994Z 0 [Note] InnoDB: Using Linux native AIO
2019-02-01T07:56:07.053336Z 0 [Note] InnoDB: Number of pools: 1
2019-02-01T07:56:07.053443Z 0 [Note] InnoDB: Using CPU crc32 instructions
2019-02-01T07:56:07.055009Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2019-02-01T07:56:07.055061Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
2019-02-01T07:56:07.055067Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2019-02-01T07:56:07.055073Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2019-02-01T07:56:07.055081Z 0 [ERROR] Plugin ‘InnoDB‘ init function returned error.
2019-02-01T07:56:07.055085Z 0 [ERROR] Plugin ‘InnoDB‘ registration as a STORAGE ENGINE failed.
2019-02-01T07:56:07.055088Z 0 [ERROR] Failed to initialize builtin plugins.
2019-02-01T07:56:07.055091Z 0 [ERROR] Aborting

2019-02-01T07:56:07.055108Z 0 [Note] Binlog end
2019-02-01T07:56:07.055159Z 0 [Note] Shutting down plugin ‘CSV‘
2019-02-01T07:56:07.055380Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

 

可见是内存不够用了,导致的oom问题。继续用free -m查看内存,发现如下:

free -m
              total        used        free      shared  buff/cache   available
Mem:            992         270         107          50         614         496
Swap:             0           0           0

 

内存不够只有107M空间可用,swap可用空间为0。

 

所以解决方案有两个:

一:修改/etc/my.inf文件,将innodb_buffer_pool_size改小

innodb_buffer_pool_size = 32M

 

 

二:增加swap文件

具体步骤参见:在CentOS 7上添加Swap交换空间

 

至此问题解决。

-----------------------------------------

有问题不怕,解决思路很重要!

以上是关于Mysql自动宕机:InnoDB: Cannot allocate memory for the buffer pool的主要内容,如果未能解决你的问题,请参考以下文章

MySQL无法启动——cannot allocate the memory for the buffer pool

MySQL的Binlog与主从复制

MySQL中InnoDB脏页刷新机制Checkpoint

mysql集群无法启动成功

数据库添加外键错误:[Err] 1215 - Cannot add foreign key constraint 的解决

故障处理[ERROR] InnoDB: File (unknown): 'read' returned OS error 0. Cannot continue operation