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交换空间

 

至此问题解决。

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

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM