A frequently occurred problem that makes your Drupal or other CMS fail is: 

PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (111) in lock_may_be_available() (line 167 of /var/www/drupal­

I saw many people asking this problem online, but did not see any viable answers. After Googling for hours, I finally came up with a solution. Let me start with what causes this problem. 

Why this problem happens?

The error mainly happens due to the insufficient memory on the heap for the mySQL on EC2. The Amazon EC2′s micro instance gives us just 613MB of memory and mySQL can’t take all of the memory for itself.
InnoDB memory heap is disabled in mySQL is an annoying issue that occurs pretty often when you install mySQL on Amazon EC2 server, especially when you use it for Drupal or WordPress. Let’s now look at why this error happens and how we could trouble shoot it.

How to solve this issue?

The solution that works best is to create a swap memory for mySQL and allow the applications to take advantage of that. Here’s how to do that:
  1. Login into your instance from Terminal or Command Prompt via SSH.
  2. Now, switch to Root mode (Sudo su)
  3. Run the following command: dd if=/dev/zero of=/swapfile bs=1M count=1024
  4. Make a swap file by running: mkswap /swapfile 
  5. Turn on Swap Files: swapon /swapfile
And that’s it. You’re done. To monitor your Swap file size and free space, just type swapon -s.

Hope this helps. 
This problem used to happy to me quite frequently on daily base. After using this method, my Drupal has been work perfectly for days.  


Popular Posts