MySQL Server Keeps Stopping – Troubleshooting and Fixes

MySQL

I'm running mysql on an Ubuntu server and for some reason, mysql has been shutting down unexpectedly. Usually I can start it back up again, but now it won't start. I don't know what version I'm running, and don't know how to find out. I can't even find any logs for mysql so I have no idea what's going on at all, given that I'm even looking in the right place for logs. I'm really lost here, can someone point me in the right direction?

EDIT:

Ok, after finding out I can look in the syslog for some information, I found this which might be helpful:

Jun 18 12:37:39 ip-10-98-167-102 kernel: [6892262.992944] Out of memory: Kill process 2351 (mysqld) score 95 or sacrifice child
Jun 18 12:37:39 ip-10-98-167-102 kernel: [6892262.992961] Killed process 2351 (mysqld) total-vm:689332kB, anon-rss:57548kB, file-rss:0kB
Jun 18 12:37:39 ip-10-98-167-102 kernel: [6892263.072544] init: mysql main process (2351) killed by KILL signal
Jun 18 12:37:39 ip-10-98-167-102 kernel: [6892263.073876] init: mysql main process ended, respawning
Jun 18 12:37:40 ip-10-98-167-102 kernel: [6892263.872080] type=1400 audit(1340023060.184:20): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=7068 comm="apparmor_parser"
Jun 18 12:37:41 ip-10-98-167-102 kernel: [6892265.330749] init: mysql main process (7072) terminated with status 1

Best Answer

That log explains why MySQL died. It was killed by the OOM-killer. The OOM killer is a fun part of Linux that exists because Linux over-promises RAM to processes and then, when they actually want the RAM they've been promised, it kills one of them to give the others the RAM they want.

It chooses which one to kill based on an algorithm that seems to rank MySQL very highly. Probably because it uses a lot of RAM.

I would suggest running mysqltuner.pl (Get it with wget mysqltuner.pl) on your MySQL box and also looking at the output of top to see which processes are using all your memory.