Mysql cannot allocate memory for the buffer pool 解决方法

今天打开网站提示数据库连接失败,吓我一跳,赶紧查日志,果然数据库服务挂了,具体日志如下

190605 8:35:19 [Note] /usr/libexec/mysqld (mysqld 5.5.56-MariaDB) starting as process 10509 …
190605 8:35:19 InnoDB: The InnoDB memory heap is disabled
190605 8:35:19 InnoDB: Mutexes and rw_locks use GCC atomic builtins
190605 8:35:19 InnoDB: Compressed tables use zlib 1.2.7
190605 8:35:19 InnoDB: Using Linux native AIO
190605 8:35:19 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137756672 bytes) failed; errno 12
190605 8:35:19 InnoDB: Completed initialization of buffer pool
190605 8:35:19 InnoDB: Fatal error: cannot allocate memory for the buffer pool
190605 8:35:19 [ERROR] Plugin ‘InnoDB’ init function returned error.
190605 8:35:19 [ERROR] Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed.
190605 8:35:19 [ERROR] mysqld: Out of memory (Needed 128917504 bytes)
190605 8:35:19 [Note] Plugin ‘FEEDBACK’ is disabled.
190605 8:35:19 [ERROR] Unknown/unsupported storage engine: InnoDB
190605 8:35:19 [ERROR] Aborting

190605 8:35:19 [Note] /usr/libexec/mysqld: Shutdown complete

190605 08:35:19 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended

大致的意思,就是没法为缓存池分配128M的内存。这个嘛,可以理解,这台主机只有1G内存,好吧,查查资料,说这个缓存池主要用来缓存innodb的索引,好了,不废话了,怎么解决呢

在配置文件中,有一个选项是用来调整缓存大小的,如果你没有这个选项,或者注释了,那默认就是128M,具体你可以去查查文档。所以,你要么把这个值改小一点,比如50M。我选择重启服务器。

innodb_buffer_pool_size = 128M

如果你还要进一步优化,很简单:1,加内存;2,加虚拟缓存。后者治标,前者治本。

此条目发表在mysql分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注