今天早上上班,發現自己使用wordpress搭建的網站不能訪問,報如下錯誤:
Error establishing a database connection
趕緊登到自己阿里雲服務器(centos7.4)查看mysql服務,通過ps -ef | grep mysql 發現已經沒有了mysql進程。
首先要做的是查看mysql日志,通過vi /var/log/mysqld.log果然發現對應的錯誤異常:
2018-12-26T02:06:16.148626Z 0 [Note] Event Scheduler: Purging the queue. 0 events "/var/log/mysqld.log" 623L, 59293C 2019-02-01T07:56:07.052989Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier 2019-02-01T07:56:07.052991Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-02-01T07:56:07.052994Z 0 [Note] InnoDB: Using Linux native AIO 2019-02-01T07:56:07.053336Z 0 [Note] InnoDB: Number of pools: 1
2019-02-01T07:56:07.053443Z 0 [Note] InnoDB: Using CPU crc32 instructions 2019-02-01T07:56:07.055009Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M 2019-02-01T07:56:07.055061Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
2019-02-01T07:56:07.055067Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool 2019-02-01T07:56:07.055073Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error 2019-02-01T07:56:07.055081Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2019-02-01T07:56:07.055085Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2019-02-01T07:56:07.055088Z 0 [ERROR] Failed to initialize builtin plugins.
2019-02-01T07:56:07.055091Z 0 [ERROR] Aborting 2019-02-01T07:56:07.055108Z 0 [Note] Binlog end
2019-02-01T07:56:07.055159Z 0 [Note] Shutting down plugin 'CSV' 2019-02-01T07:56:07.055380Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
可見是內存不夠用了,導致的oom問題。繼續用free -m查看內存,發現如下:
free -m total used free shared buff/cache available Mem: 992 270 107 50 614 496 Swap: 0 0 0
內存不夠只有107M空間可用,swap可用空間為0。
所以解決方案有兩個:
一:修改/etc/my.inf文件,將innodb_buffer_pool_size改小
innodb_buffer_pool_size = 32M
二:增加swap文件
具體步驟參見:在CentOS 7上添加Swap交換空間
至此問題解決。
-----------------------------------------
有問題不怕,解決思路很重要!
