Centos7 MySQL 错误 InnoDB: Cannot allocate memory for the buffer pool

最近MySQL总是崩溃,上错误日志

[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
[Note] /usr/sbin/mysqld (mysqld 5.7.21) starting as process 19767 ...
[Note] InnoDB: PUNCH HOLE support available
[Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
[Note] InnoDB: Uses event mutexes
[Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
[Note] InnoDB: Compressed tables use zlib 1.2.3
[Note] InnoDB: Using Linux native AIO
[Note] InnoDB: Number of pools: 1
[Note] InnoDB: Using CPU crc32 instructions
[Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
[ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
[ERROR] InnoDB: Cannot allocate memory for the buffer pool
[ERROR] InnoDB: Plugin initialization aborted with error Generic error
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[ERROR] Failed to initialize builtin plugins.
[ERROR] Aborting

很多解决方案都是直接给出了增加 SWAP , 试了很多方法就是添加不上,free半天还是0。

要将正确的路径加入到fstab中才行,很多教程省略了路径。

再次记录一下操作步骤。

cd /var/

添加SWAP文件快,2GB
dd if=/dev/zero of=swapfile bs=1M count=2048

创建SWAP文件
/sbin/mkswap swapfile

激活SWAP文件
/sbin/swapon swapfile

查看SWAP信息是否正确
/sbin/swapon –s

添加到fstab文件
echo "/var/swapfile swap swap defaults 0 0" >>/etc/fstab

完事了,free 可查看内存和swap情况。

posted @ 2019-10-18 16:22  光和环  阅读(688)  评论(0)    收藏  举报