修的了电脑 敲得了代码
     写得了前端 稳得住后端

Centos7 MySQL 错误 InnoDB: Cannot allocate memory for the buffer pool。解决办法:添加swap

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

2023-01-28 10:58:23 0 [Note] InnoDB: Using Linux native AIO
2023-01-28 10:58:23 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2023-01-28 10:58:23 0 [Note] InnoDB: Uses event mutexes
2023-01-28 10:58:23 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2023-01-28 10:58:23 0 [Note] InnoDB: Number of pools: 1
2023-01-28 10:58:23 0 [Note] InnoDB: Using SSE2 crc32 instructions
2023-01-28 10:58:23 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2023-01-28 10:58:23 0 [ERROR] InnoDB: mmap(137035776 bytes) failed; errno 12
2023-01-28 10:58:23 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2023-01-28 10:58:23 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2023-01-28 10:58:23 0 [Note] InnoDB: Starting shutdown...
230128 10:58:24 [ERROR] mysqld got signal 11 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.

To report this bug, see https://mariadb.com/kb/en/reporting-bugs

We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed, 
something is definitely wrong and this may fail.

Server version: 21.2.98-MariaDB
key_buffer_size=134217728
read_buffer_size=131072
max_used_connections=0
max_threads=153
thread_count=0
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 467424 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0x0 thread_stack 0x49000

解决办法:

很多解决方案都是直接给出了增加 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情况。

赞(3)
未经允许不得转载:流云溪|码农 » Centos7 MySQL 错误 InnoDB: Cannot allocate memory for the buffer pool。解决办法:添加swap