Linux下mysql程序死掉,InnoDB: mmap(137363456 bytes) failed; errno 12解決方法
阿新 • • 發佈:2018-11-02
這個問題一直困擾了我很久,在網上查找了很多資料一直沒解決我的問題,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分割槽
[[email protected]_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
[[email protected]_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
[[email protected]_0_17_centos bin]# sudo mkswap /swapfile
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=3d2b10de-c987-451e-b020-59ef3bf0a19b
[[email protected]_0_17_centos bin]# sudo swapon /swapfile
swapon: /swapfile: insecure permissions 0644, 0600 suggested.
[[email protected]_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!