Fork me on GitHub

mmap(xxx bytes) failed; errno 12解决方法

缘由

已经两三次英国同事找到我说网站除了首页其他页面都访问不了了,然后迅速看了下网站,发现日志如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
160605 20:55:51 mysqld_safe mysqld restarted
160605 20:55:52 [Note] Plugin 'FEDERATED' is disabled.
160605 20:55:52 InnoDB: The InnoDB memory heap is disabled
160605 20:55:52 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160605 20:55:52 InnoDB: Compressed tables use zlib 1.2.3
160605 20:55:52 InnoDB: Using Linux native AIO
160605 20:55:52 InnoDB: Initializing buffer pool, size = 64.0M
InnoDB: mmap(68681728 bytes) failed; errno 12
160605 20:55:52 InnoDB: Completed initialization of buffer pool
160605 20:55:52 InnoDB: Fatal error: cannot allocate memory for the buffer pool
160605 20:55:52 [ERROR] Plugin 'InnoDB' init function returned error.
160605 20:55:52 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
160605 20:55:52 [ERROR] Unknown/unsupported storage engine: InnoDB
160605 20:55:52 [ERROR] Aborting

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
160606 10:46:03 InnoDB: The InnoDB memory heap is disabled
160606 10:46:03 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160606 10:46:03 InnoDB: Compressed tables use zlib 1.2.3
160606 10:46:03 InnoDB: Using Linux native AIO
160606 10:46:03 InnoDB: Initializing buffer pool, size = 64.0M
160606 10:46:03 InnoDB: Completed initialization of buffer pool
160606 10:46:03 InnoDB: highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 2189254361
160606 10:46:04 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 2189254381
InnoDB: Last MySQL binlog file position 0 143701705, file name ./mysql-bin.000016

果然是挂了,发现是mysql的问题,之后试着重启了下mysql就好了,任务多就没多大体会,然后就搁置了。

正好找了空今天把这个问题解决了,解决方法当然是google了,这么好的工具不用浪费啦,发现原来是swap问题。O(∩_∩)O哈哈~

解决方法:

在 /etc/my.cnf 的 mysqld 下增加下面一句:

1
innodb_buffer_pool_size = 512M

设置一下swap分区,通过fdisk -l 和 1mount 看不到swap的信息,需要手动添加一下。

1
2
3
4
dd if=/dev/zero of=/swapfile bs=1M count=1024
mkswap /swapfile
swapon /swapfile
添加这行: /swapfile swap swap defaults 0 0 到 /etc/fstab

重启mysql

1
/etc/init.d/mysqld restart

或者

1
service mysqld restart

参考链接: