How to fix MariaDB from being killed

September 11, 2016 847 views
MariaDB WordPress

I have a $5/month CentOS 7.2 x64 droplet (512MB/1 CPU) on Digital Ocean to run a Wordpress Site and small PHP/SQL based application. I have created a 4GB swap file on the system since there was nothing setup initially.

> free -m
              total        used        free      shared  buff/cache   available
Mem:            993         643         113           2         236         188
Swap:          3999          94        3905

For some reason MariaDB keeps shutting down. When I check the status of it, it is inactive

> service mariadb status
Redirecting to /bin/systemctl status  mariadb.service
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Thu 2016-09-08 10:40:28 UTC; 24h ago
  Process: 816 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 815 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS)
  Process: 735 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 815 (code=exited, status=0/SUCCESS)

When I run top, sorting on %MEM, httpd and mysqld are the top results for the amount of memory used

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                 
 4854 mysql     20   0 1106344  98940   9728 S  0.0  9.7   0:33.06 mysqld                                  
 4186 apache    20   0  551992  65244   8636 S  0.0  6.4   0:24.45 httpd                                   
 4900 apache    20   0  551536  65120   8852 S  0.0  6.4   0:14.35 httpd                                   
 4174 apache    20   0  551768  64060   7840 S  0.0  6.3   0:22.45 httpd                                   
 4187 apache    20   0  551552  63760   7856 S  0.0  6.3   0:23.90 httpd                                   
 4191 apache    20   0  551412  63700   7848 S  0.0  6.3   0:25.82 httpd                                   
 4179 apache    20   0  551060  63360   7848 S  0.0  6.2   0:24.64 httpd                                   
 4924 apache    20   0  549700  62476   8156 S  0.0  6.1   0:12.42 httpd                                   
 4190 apache    20   0  549460  61740   7844 S  0.0  6.1   0:27.40 httpd                                   
 5879 apache    20   0  533824  56216   4836 S  0.0  5.5   0:01.06 httpd                                   
 5885 apache    20   0  519680  40932   4460 S  0.0  4.0   0:00.40 httpd                                   

I believe the system is running out of memory and killing MariaDB.

How do I fix MariaDB so it doesn't keep dying?

2 Answers

Upgrade to a bigger droplet? Do you cache your website? Use cloudflare?

Have another answer? Share your knowledge.