Amazon EC2 Micro mySQL Service Crash Issue Resolved!

By January 10, 2014 February 18th, 2015 IT Stuffs

I created few websites with Amazon EC2 Micro server and never understand why mySQL server service crashes every once a while, even when the web site is extremely small with few simple pages only (this is the reason we choose “micro” isn’t it?)  At the end, I realized the ubuntu server micro image from Amazon does not have swap partition, and I believe this is the reason why mySQL service keep crashing.  mySQL service likes swap, so we should give him one.  Here is how:

  • ssh into your Amazon micro server
  • “sudo su -” so you have the full root permission
  • type the following command to create a 1GB swap space.  Of course, before you do this, make sure you do have 1GB free HDD space on the server.  It will take some time to create the new swap space.
    • dd if=/dev/zero of=/swapfile bs=1M count=1024
  • Once it is created, you should see something like this on the screen:
    • 1024+0 records in
    • 1024+0 records out
    • 1073741824 bytes (1.1 GB) copied, 42.0382 s, 25.5 MB/s
  • Now, let’s create a folder called “swapfile” and make it as a swap parition
    • mkswap /swapfile
  • And to enable the swap partition, use the following command:
    • swapon /swapfile
  • This is it.  It is good to add the swap partition in the /etc/fstab so the swap partition will stay after each reboot:
    • /swapfile swap swap defaults 0 0

Happy swapping!

Join the discussion One Comment

  • Johnc864 says:

    Specifically where web can a certified psyciatrist submit content or sites for them to become fashionable? gddcacdckcae

Leave a Reply