this has driven me crazy, I just couldn't find out what is wrong with it.

I moved my site onto a test directory under my domain '/drupal_test', I have transferred the database over, set up everything properly, and then I got this error:

PDOException: SQLSTATE[HY000] [2013] Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in lock_may_be_available() (line 167 of /var/www/drupal_test/includes/lock.inc). 

I have set up settings.php like this:

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'websitedb',
      'username' => 'websitedbnm',
      'password' => 'thepass',
      'host' => 'xxx.xxx.xxx.xxx',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',

I am really sure all the data is right. I can connect to my database through command lines using this account and I can also see all the right tables in this database.

I also tried commenting and editing this line:

$base_url = 'http://www.example.com/drupal_test';  // NO trailing slash!

I still get this error and can't see my site...what could have gone wrong?


7 Answers 7


If you are pretty much sure that database credentials are correct than please verify the database hostname because the reason of the above error is database configuration only.


To share a bit more detail: the reason for this is generally that your MySQL GRANT is configured as user@localhost. Therefore, connecting over the external IP address does not match the @localhost portion, and your connection is rejected. Specifically, because no users in the mysql.user table match the external address in their host column, the connection is rejected immediately. You can see this by the simple expedient of telneting to the port:

$ telnet example.com 3306
Connected to example.com.
Escape character is '^]'.
FHost '' is not allowed to connect to this MySQL serverConnection closed by foreign host.

As you can see, before authentication is even attempted, the connection is killed. If you had a host entry that could have satisfied this request, you would have gotten an authentication failed message, instead. But in this case, the connection died before authentication was even requested or sent, thus the lost connection at "reading initial communication packet"; the very first packet sent included a disconnection!

To resolve this, either use a hostname value in your databases array for which there will be a corresponding host column entry in the mysql.user table, or add an explicit grant that covers the use case, e.g.:

GRANT ALL ON drupal.* TO 'drupal'@'' IDENTIFIED BY 'YjbW7dUT';

Note that you can also use '%' as a wildcard, as in:

GRANT ALL ON drupal.* TO 'drupal'@'255.0.0.%' IDENTIFIED BY 'YjbW7dUT';

or even:

GRANT ALL ON drupal.* TO 'drupal'@'%' IDENTIFIED BY 'YjbW7dUT';

Don't use this last one unless you have a firewall in front of your MySQL server. (Which you already have anyway, right? Right.)

Bonus Section

MySQL treats localhost specially. Specifically, localhost means to use the UNIX socket, whereas means to use TCP/IP networking. Therefore, you can run into the strange case where the two are not interchangeable, despite the fact that in every other part of the *NIX world, they are. This can commonly happen when you have skip-name-resolve specified in your my.cnf; your GRANTs for localhost now don't cover access over TCP/IP, and vice versa.

To fix, either add a localhost GRANT for each one (and vice versa), or change all host columns in the user table to %—which, at the risk of repeating myself from earlier, should only be done if you are behind a firewall in which you are eminently confident.


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


I had the same error, but the database configuration was correct.

I'm using a multisite configuration.

I knew the config was right because it was the same for other sites.

The error was in sites.php, the new site was not added to the list, once added it started to work again.

Writing this answer in case anyone has a similar issue. :)


In MySQL speak, system error 111 is ECONNREFUSED (e.g. from connect(2): "No one listening on the remote address."). This means that the client library was unable to connect to the database server. Either you spelled the server name/IP wrong, used the wrong port, or the server is not running and/or listening on the specified port at all.

To check if the server is there, run the command:

# 3306 is the standard MySQL port. Change if using other.
$ telnet mysql.example.com 3306

Don't be fooled by the "Lost connection" in the error message -- there never were a connection at first place.


For others who might stumble upon this question after their local Acquia Dev Desktop database suddenly stopped working after importing a database from a remote cloud server: restarting the Apache and MySQL servers fixed the error for me.


You must enable SSH TCP forwarding otherwise packets will drop.

In /etc/ssh/sshd_config:

#AllowTcpForwarding yes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.