MariaDB出现'Fatal error: cannot allocate memory for the buffer pool'错误的解决办法

By | November 25, 2016

最后更新时间: 2020-06-13 14:53:30

MariaDB出现'Fatal error: cannot allocate memory for the buffer pool'错误的解决办法

Updated On: 2020-06-13

Created On: 不详

今早网站的数据库连接失败,登录服务器发现mysqld进程已经退出,查看日志,出现了如下的内容:

10:59:23 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
11:03:34 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
11:03:34 [Note] /usr/libexec/mysqld (mysqld 5.5.50-MariaDB) starting as process 22883 ...
11:03:34 InnoDB: The InnoDB memory heap is disabled
11:03:34 InnoDB: Mutexes and rw_locks use GCC atomic builtins
11:03:34 InnoDB: Compressed tables use zlib 1.2.7
11:03:34 InnoDB: Using Linux native AIO
11:03:34 InnoDB: Initializing buffer pool, size = 256.0M mmap(275513344 bytes) failed; errno 12
11:03:34 InnoDB: Completed initialization of buffer pool
11:03:34 InnoDB: Fatal error: cannot allocate memory for the buffer pool
11:03:34 [ERROR] Plugin 'InnoDB' init function returned error.
11:03:34 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
11:03:34 [ERROR] mysqld: Out of memory (Needed 128917504 bytes)
11:03:34 [Note] Plugin 'FEEDBACK' is disabled.
11:03:34 [ERROR] Unknown/unsupported storage engine: InnoDB
11:03:34 [ERROR] Aborting
11:03:34 [Note] /usr/libexec/mysqld: Shutdown complete
11:03:35 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.p     id ended

于是,第一时间修改数据库服务器配置文件,修改(没有则添加):innodb_buffer_pool_size=256M (原来为128M),保存文件,启动Mysqld进程,仍然启动不了。

top一下,发现apache占用的内存过多。原来是系统内存不够用。停掉httpd进程,然后再次尝试启动mysqld,这时顺利启动。于此就应该去限制apache的进程/线程数量,这要修改的是MPM模式的配置内容,以小内存的服务器为例(按实际情况调节),假设用的是Event模式,在htttpd.conf文件中修改后的内容如下:

<IfModule mpm_event_module>
StartServers           3
ServerLimit 16
MinSpareThreads        3
MaxSpareThreads        5
ThreadsPerChild        8
MaxRequestWorkers    32
MaxConnectionsPerChild   32
</IfModule>

修改完成启动Apache,启动成功。至于Apache的内存占用情况还须观察一下。

鉴于本人的相关知识储备以及能力有限,本博客的观点和描述如有错漏或是有考虑不周到的地方还请多多包涵,也欢迎指正,一起学习,共同进步。如果本文对您有帮助,而且让您觉得值得为内容付费,那么就请赞助(打赏)一下本人,这不强制。打赏支持微信支付,方法是使劲地戳一下下方的“打赏”按钮,然后得到微信收款的二维码,再用微信支付扫一下,就像买菜那样。祝好!