srik.in

Understanding socket connection errors in Drupal and how to solve them

Introduction

user

Srikanth Eswaran

Srikanth Eswaran has seen nearly three decades of lifestyle across three generations starting from India being the land of snake charmers to the country becoming the next infrastructural superpower. In this time, he has been through some demanding situations, trials and tribulations which has made him a polished and mature individual who is now poised to handle what life throws at him. His interests lie in writing, discussing online, photography, web-design, software project management and methodologies and automobiles to name a few.


pdoexception, socket, errors, drupal

Understanding socket connection errors in Drupal and how to solve them

Posted by Srikanth Eswaran on .
Featured

pdoexception, socket, errors, drupal

Understanding socket connection errors in Drupal and how to solve them

Posted by Srikanth Eswaran on .

In this post I will briefly record how to resolve the following error

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­
7.22/includes/lock.inc).

This is a frustrating error which has made me go back to my web hosts and understand from them why this error repeated occurs. The biggest drawback of this error is that all drupal installations come to a halt for good and its a big journey from there until you screw up your databases, screw up your content and further are so misled by all explanations on the internet until you feel you are a dumbass for having to use drupal in the first place.

This is the cost of experimental software contributed by a community. Thankfully, Jeffery Yee has provided a solution for this and this is what you need to do to enjoy drupaling all over again.

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:

  • Login into your instance from Terminal or Command Prompt via SSH.
  • Now, switch to Root mode (Sudo su)
  • Run the following command: dd if=/dev/zero of=/swapfile bs=1M count=1024
  • Make a swap file by running: mkswap /swapfile
  • 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.

user

Srikanth Eswaran

http://srik.in

Srikanth Eswaran has seen nearly three decades of lifestyle across three generations starting from India being the land of snake charmers to the country becoming the next infrastructural superpower. In this time, he has been through some demanding situations, trials and tribulations which has made him a polished and mature individual who is now poised to handle what life throws at him. His interests lie in writing, discussing online, photography, web-design, software project management and methodologies and automobiles to name a few.