Linux下mysql进程死掉,InnoDB: mmap(137363456 bytes) failed; errno 12解决方法

这个问题一直困扰了我很久,在网上查找了很多资料一直没解决我的问题,mysql卸载一次又装一次还是会有这个问题.

问题还原:mysql启动时是SUCCESS!但是过了一段时间,进程就死掉了,远程连接失败,重启mysql会报错,错误信息如下:

Starting MySQL../usr/local/mysql//bin/mysqld_safe: line 166:  9086 Killed                  nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/mysql/VM_0_17_centos.err --pid-file=/usr/local/mysql/data/mysql/VM_0_17_centos.pid < /dev/null >> /usr/local/mysql/data/mysql/VM_0_17_centos.err 2>&1
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/mysql/VM_0_17_centos.pid).

按照提示的目录查看错误详细的信息如下:

2018-10-09 15:11:54 1854 [Note] InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
2018-10-09 15:11:54 1854 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2018-10-09 15:11:54 1854 [ERROR] Plugin 'InnoDB' init function returned error.
2018-10-09 15:11:54 1854 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2018-10-09 15:11:54 1854 [ERROR] Unknown/unsupported storage engine: InnoDB
2018-10-09 15:11:54 1854 [ERROR] Aborting

可以看到错误的关键信息在于InnoDB: mmap(137363456 bytes) failed; errno 12,网上有很多建议修改my.cnf配置文件innodb_buffer_pool_size参数,改大改小我都试过了,还是没有用.然后又仔细的查了网上的建议,通过free指令知道了我刚买的服务器没有配置Swap分区

[root@VM_0_17_centos bin]# free
              total        used        free      shared  buff/cache   available
Mem:        1016288      475944      381680         368      158664      385936
Swap:             0           0           0

关于Swap分区可以参见百度百科(Swap分区),知道了当前问题的源头就给机器配置一个Swap分区大小1G

[root@VM_0_17_centos bin]# sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 0.998251 s, 1.1 GB/s
[root@VM_0_17_centos bin]# sudo mkswap /swapfile
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=3d2b10de-c987-451e-b020-59ef3bf0a19b
[root@VM_0_17_centos bin]# sudo swapon /swapfile
swapon: /swapfile: insecure permissions 0644, 0600 suggested.
[root@VM_0_17_centos bin]# free
              total        used        free      shared  buff/cache   available
Mem:        1016288      475220       62760         368      478308      381388
Swap:       1048572           0     1048572

关于设置Swap分区大小可以参考 linux SWAP大小与内存的关系

执行完毕后查看Swap分区大小为1048572KB.然后重启mysql,SUCCESS!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值