Score:-1

Unable to connect to database when launching a new Drupal site with Lando

zm flag

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.

id flag
I thought that Lando runs the database server on a different host, named "db" or similar, not "localhost".
cn flag
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
leymannx avatar
ne flag
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`.
shibasaki_stack avatar
zm flag
Thank you. I changed it to database as commented below and it worked fine. Where can I find this hostname?
Score:1
fr flag

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

localhost is not correct for default lando configuration.

shibasaki_stack avatar
zm flag
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.
No Sssweat avatar
ua flag
@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.
shibasaki_stack avatar
zm flag
OK, I found it. thanks.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.