when starting an existing project on another computer. As the repository wasn't online already, I had to copy the whole D7 folder from PC1 to PC2, and import the database in phpMyAdmin. I've got this error as result when accessing my (localhost) homepage.

PDOException: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'localhost' (10061) in lock_may_be_available()
plz help me


drnikki’s picture

When I get this error, it's always something wrong in settings.php. Take another look at what you've got in there for your db settings -- it sounds like the db info is different from PC1 to PC2.

omki’s picture

Got similar error after site was disabled, put offline during a backup.
When site came online this error showed for the Drupal MySQL DB.

If moving to new hardware or network, etc. The contents of the 'settings.php' will have to be updated.

1. Locate the 'settings.php' file (should be in [drupal home dir]/sites/default/settings.php)
a. Find the "$databases = array ( 'default' => ..........." entry
b. The above should have the name of your database and user account information.

Make sure the appropriate database name, user name, etc. are specified in this file.

NOTE: the settings.php file has permissions set to read-only. You will have to temporarily change this to Read-Write to modify it - then change it back when done.

imoghis’s picture

I checked my settings and its correct but it's strange how I still get that error. I am on Amazon web services and I have my RDS database instance connected to my EC2.

I can connect through the shell but on the browser it gives me that exception.

Really strange. Any suggestions ppl?

justinbaeder’s picture

Sorry if this is obvious to others, but I wanted to make a note for myself that this is in /sites/default/settings.php.

I moved to a new server and had to update my database username, password, and host.

Thanks for explaining this error message!

Mikex’s picture

I had the same problem, but I have a doubt. I want to know how I configure my database("settings.php") to be accessible from any PC that I can use to manage my site.

alxbridge’s picture

I had this problem when installing a site on a CentOS server, connecting to a database on another server. It turned out the connection to the database was being prevented by SELinux. Issuing the following command (as root) told SELinux to allow the connection:

setsebool httpd_can_network_connect_db=1

cyberswat’s picture

@alxbridge, Thank you for posting this.

GwenMahe’s picture

That was it for me. Thx!

Ummy007’s picture

Best way to handle this error is when you switch your drupal website from one host to another that delete your settings.php file
and switch to host where you place your drupal website .then it ask to install drupal and their are two option first add new site and second use previous site if we select second option then your drupal site will appear their and new settings.php created automatically with require configuration...I solved problem this way

imoghis’s picture

So do you have a fresh install of Drupal 7 or your previous site installed on the web server?

Let me know. Thanks.

imoghis’s picture

This so worked for me in terms of permissions problems and database.


For AWS support on drupal on EC2 and RDS, this youtube vid was great and on the money.


BongoNets’s picture

mpimwood’s picture

Thats a perfect solution

kjala’s picture

We had the same problme on one of our Drupal Systems. The problem happened after restarting the webServer. The Error message was

PDOException: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'My_Server_IP' (13) in lock_may_be_available() (line 167 of /var/www/html/includes/lock.inc).

We did not have any problem conencting to Mysql from command line on the same server but the Drupal PHP Code had the above issue. SELinux was enabled after the server was restarted. Permanently disabling SELinux resolved the issue. Update the file /etc/selinux/config and add/update this line