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 @   光和环  阅读(656)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· 单线程的Redis速度为什么快?
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
点击右上角即可分享
微信分享提示