从迁移到Amazon lightsail后,每隔一段时间网站数据库就宕机一次,提示:

Error establishing a database connection

查看日志shell cat mysql.log | grep ERROR


    Line 255: 2022-08-18T13:30:55.403154Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
    Line 256: 2022-08-18T13:30:55.403166Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
    Line 257: 2022-08-18T13:30:55.403173Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    Line 257: 2022-08-18T13:30:55.403173Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    Line 257: 2022-08-18T13:30:55.403173Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    Line 258: 2022-08-18T13:30:55.403182Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
    Line 258: 2022-08-18T13:30:55.403182Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
    Line 259: 2022-08-18T13:30:55.403186Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    Line 260: 2022-08-18T13:30:55.403190Z 0 [ERROR] Failed to initialize builtin plugins.
    Line 261: 2022-08-18T13:30:55.403194Z 0 [ERROR] Aborting
    Line 278: 2022-08-18T13:30:57.168382Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
    Line 279: 2022-08-18T13:30:57.168398Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
    Line 280: 2022-08-18T13:30:57.168405Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    Line 280: 2022-08-18T13:30:57.168405Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    Line 280: 2022-08-18T13:30:57.168405Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    Line 281: 2022-08-18T13:30:57.168414Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
    Line 281: 2022-08-18T13:30:57.168414Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
    Line 282: 2022-08-18T13:30:57.168432Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    Line 283: 2022-08-18T13:30:57.168441Z 0 [ERROR] Failed to initialize builtin plugins.
    Line 284: 2022-08-18T13:30:57.168445Z 0 [ERROR] Aborting
    Line 301: 2022-08-18T13:30:58.755042Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
    Line 302: 2022-08-18T13:30:58.755051Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
    Line 303: 2022-08-18T13:30:58.755066Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    Line 303: 2022-08-18T13:30:58.755066Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    Line 303: 2022-08-18T13:30:58.755066Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    Line 304: 2022-08-18T13:30:58.755075Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
    Line 304: 2022-08-18T13:30:58.755075Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
    Line 305: 2022-08-18T13:30:58.755079Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    Line 306: 2022-08-18T13:30:58.755083Z 0 [ERROR] Failed to initialize builtin plugins.
    Line 307: 2022-08-18T13:30:58.755086Z 0 [ERROR] Aborting
    Line 324: 2022-08-18T13:31:00.509921Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
    Line 325: 2022-08-18T13:31:00.509935Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
    Line 326: 2022-08-18T13:31:00.509942Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    Line 326: 2022-08-18T13:31:00.509942Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    Line 326: 2022-08-18T13:31:00.509942Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
    Line 327: 2022-08-18T13:31:00.509951Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
    Line 327: 2022-08-18T13:31:00.509951Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
    Line 328: 2022-08-18T13:31:00.509955Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    Line 329: 2022-08-18T13:31:00.509958Z 0 [ERROR] Failed to initialize builtin plugins.

"InnoDB: Cannot allocate memory for the buffer pool" ===> 无法为缓冲池分配内存

估计因为用的aws轻量最低配的原因,内存本身就只有512M,少的可怜。查看下内存情况:

[root@log]# free -m
              total        used        free      shared  buff/cache   available
Mem:            485         285          7           8         181         178
Swap:             0           0           0

仅剩7M,swap为0。

好吧,修改:

innodb_buffer_pool_size = 32M

再观察两天看看,也加了定时每天重启mysql。