Connection timed out and lock_may_be_available() on working site I'm hoping someone can point me to a fix. My drupal 7 app was running fine locally this a.m. while I was testing a way to insert a row using mysql tools for a non-Drupal function. My environment is Apache running virtual host on php 5.4.34 on a Ubuntu VM. 

After not getting satisfaction using the mysql functions, I started a simple PDO function using Drupal's database settings from the settings.php file. I was able to insert a row successfully but when I returned to the local site I got this error after a long time:

drupal_log_error(Array ([%type] =&gt; PDOException,[!message] =&gt; SQLSTATE[HY000] [2002] Connection timed out,[%function] =&gt; lock_may_be_available(),[%file] =&gt; /media/psf/Home/apps/habitatnashville/includes/lock.inc,[%line] =&gt; 167, etc

[%type] =&gt; PDOException
    [!message] =&gt; SQLSTATE[HY000] [2002] Connection timed out
    [%function] =&gt; lock_may_be_available()
    [%file] =&gt; /media/psf/Home/apps/habitatnashville/includes/lock.inc
    [%line] =&gt; 167
    [severity_level] =&gt; 3


I've looked here and on Drupal's site. Because it's a connection error the likely suspects are that I've munged the credentials somehow. 

When something like this happened months ago, I did a service mysql restart, did that again a few minutes ago, rebooted the ubuntu VM and rebooted entire computer to shake that lock.

I've removed that test file with the PDO just in case. Here's the output of my drush status:

Drupal version                  :  7.27                                        
 Site URI                        :  http://default                              
 Database driver                 :  mysql                                       
 Database username               :  admin                                
 Database name                   :  my_db                             
 Database                        :  Connected                                   
 Drupal bootstrap                :  Successful                                  
 Drupal user                     :  Anonymous                                   
 Default theme                   :  My_theme                                    
 Administration theme            :  rubik                                       
 PHP executable                  :  /home/sam/.phpbrew/php/php-5.4.34/bin/php   
 PHP configuration               :  /home/sam/.phpbrew/php/php-5.4.34/etc/php.i 
                                    ni                                          
 PHP OS                          :  Linux                                       
 Drush version                   :  6.2.0 


My database is running as "service mysql status" => mysql: start/running, process 1291.
What else could be affecting this?
There could be multiple reasons/thoughts: 


Are you sure mysql is running? 
Has your site got just too big for the resources allocated to mysql in the configuration?
Did you manually "emptied" all of the cache files via the database?
Low file system space on the database server
If you just moved the site to the other server and mysql is not set up to accept enough connections. 
The user you are connecting with has SELECT permissions on mysql but not DELETE or UPDATE etc.
The host settings in sites/default/settings.php doesn't matche the one from the User in the database
MySQL 5.7 does not allow root user to access a database from client app. After switching to a normal user, it solves.
Sometimes tuning xampp like on php.ini (memory_limit=256M) and my.ini (max_allowed_packet = 32M) and disable devel by drush (drush dis -y devel) also works.
...