Home | My New Hugo Project

Mysql crash - "Cannot connect to database" with Wordpress

2021-01-20

You setup that AWS EC2 and many days later you find that mysql crashed.  Why

  1.  Look in /var/log/messages  ( more /var/log/messages and search for mysql
  2.  See this...
Jan 18 04:23:07 ip-my-host-ip kernel: [7803276.802432] Out of memory: Kill pro cess 28710 (mysqld) score 192 or sacrifice child Jan 18 04:23:07 ip-my-host-ip kernel: [7803276.808288] Killed process 28710 (m ysqld) total-vm:1149068kB, anon-rss:193628kB, file-rss:0kB, shmem-rss:0kB Jan 18 04:23:07 ip-my-host-ip kernel: [7803276.839156] oom_reaper: reaped proc ess 28710 (mysqld), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB

3.   Why run out of memory - well - it has to do with swap

[root@ip-my-host-ip log]# top top - 23:06:06 up 93 days, 2:18, 1 user, load average: 0.00, 0.00, 0.00 Tasks: 98 total, 1 running, 70 sleeping, 0 stopped, 0 zombie Cpu(s): 0.1%us, 0.0%sy, 0.0%ni, 99.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 1009132k total, 828180k used, 180952k free, 74476k buffers Swap: 0k total, 0k used, 0k free, 134412k cached

 

4.  You can see on the last line - swap is 0k - so you Need to add swap


[root@ip-my-host-ip log]# fallocate -l 1G /swapfile
[root@ip-my-host-ip log]# chmod 600 /swapfile
[root@ip-my-host-ip log]# mkswap /swapfile
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=7a35f172-cded-438d-8032-f2103873794e
[root@ip-my-host-ip log]# sudo swapon /swapfile
[root@ip-my-host-ip log]# swapon --show
NAME TYPE SIZE USED PRIO
/swapfile file 1024M 0B -2
[root@ip-my-host-ip log]# free
total used free shared buffers cached
Mem: 1009132 830840 178292 368 74540 136204
-/+ buffers/cache: 620096 389036
Swap: 1048572 0 1048572

 

Note: if you have issues - try using dd to allocate swapfile.

[root@ip-my-host-ip log]# dd if=/dev/zero of=/swapfile bs=1024 count=1048576
1048576+0 records in
1048576+0 records out
1073741824 bytes (1.1 GB) copied, 6.36502 s, 169 MB/s

5.  add it to the /etc/fstab

#
LABEL=/ / ext4 defaults,noatime 1 1
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/swapfile none swap sw 0 0