I tried to set up a new local drupal9 site using Lando, but it is unable to connect to the database and I am getting the following error.

Failed to connect to your database server. The server reports the following message: SQLSTATE[HY000] [2002] No such file or directory.

Checking the Lando logs shows the following.

PDOException: SQLSTATE[HY000] [2002] No such file or directory in /app/web/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php on line 79

I checked and it seems to be resolved by putting the location of mysql.sock file in settings.php as shown below. I've got `PDOException: SQLSTATE[HY000] [2002] No such file or directory` when using drush

Then I checked mysql status and found the following.

UNIX socket:            /opt/bitnami/mysql/tmp/mysql.sock

The final result was as follows. But even if I change the host to 127.0.01, etc., the error message does not change.

$databases['default']['default'] = [
  'database' => 'drupal9',
  'username' => 'drupal9',
  'password' => 'drupal9',
  'host' => 'localhost',
  'port' => '3306',
  'driver' => 'mysql',
  'prefix' => '',
  'unix_socket' => '/opt/bitnami/mysql/tmp/mysql.sock',

If I've made any mistakes so far, please let me know. Thank you.

  • 2
    I thought that Lando runs the database server on a different host, named "db" or similar, not "localhost".
    – cilefen
    Dec 12, 2022 at 14:11
  • 2
    The host is database unless you've specified it differently in .lando.yml. And remove the socket entry in the array, you don't need that
    – Clive
    Dec 12, 2022 at 14:23
  • This wouldn't have happened with DDEV. DDEV creates the correct settings.ddev.php for you with all connection settings set correctly and includes it in the setttings.php.
    – leymannx
    Dec 12, 2022 at 19:48
  • Thank you. I changed it to database as commented below and it worked fine. Where can I find this hostname? Dec 13, 2022 at 0:25

1 Answer 1


You need to update host value in settings.php to database.

localhost is not correct for default lando configuration.

  • Thank you very much. I changed the host name to database and it started without problems. But how do I know that the host name is database? lando mysql -u drupal9 -p When I logged into mysql as above, the hostname was localhost. Dec 13, 2022 at 0:20
  • @shibasaki_stack You can use the command lando info and you will see one of the lines will be internal_connection: { host: 'database', port: '3306' }, under the database service.
    – No Sssweat
    Dec 13, 2022 at 1:31
  • OK, I found it. thanks. Dec 13, 2022 at 10:48

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