Score:0

Why does Drush crash with "SQLSTATE[HY000] [2002] No such file or directory"?

pn flag

I have an error when i try to update my db or install a module with drush.

[info] Try to validate bootstrap phase 5 [0.11 sec, 10.08 MB] [info] Unable to connect to database with message: SQLSTATE[HY000] [2002] No such file or directory. More debug information is available by running drush status. This may occur when Drush is trying to bootstrap a site that has not been installed or does not have a configured database. In this case you can select another site with a working database setup by specifying the URI to use with the --uri parameter on the command line. See drush topic docs-aliases for details. [0.11 sec, 10.31 MB] [info] Could not bootstrap at phase 5 [0.11 sec, 10.29 MB]

this is my drush status. Drupal version : 9.5.4
Site URI : http://default
DB driver : mysql
DB hostname : localhost
DB port : 3306
DB username : root
DB name : DruCar
PHP binary : /opt/homebrew/Cellar/[email protected]/8.1.15/bin/php
PHP config : /opt/homebrew/etc/php/8.1/php.ini
PHP OS : Darwin
PHP version : 8.1.15
Drush script : /usr/local/bin/drush
Drush version : 11.5.1
Drush temp : /tmp
Drush configs : /Applications/XAMPP/xamppfiles/htdocs/DruCar/recommended-project/vendor/drush/drush/drush.yml Drupal root : /Applications/XAMPP/xamppfiles/htdocs/DruCar/recommended-project/web
Site path : sites/default

anyway, i cant install anything with drush en.

Thank you anticipate.

leymannx avatar
ne flag
Get rid of XAMPP. Use [DDEV](https://ddev.readthedocs.io/en/stable/users/install/ddev-installation/). You don't need an UI, you need a tool that's optimised as a local Drupal/PHP development environment.
Score:1
id flag

This is likely the well-known situation of using localhost for the database configuration, which is interpreted by some database extensions as an instruction to use a unix socket file, and then the unix socket file is not properly configured. The usual solution is to use 127.0.0.1, the IPv4 address, instead of localhost in the database configuration. See https://serverfault.com/questions/295285/mysql-cannot-connect-via-localhost-only-127-0-0-1

Core has this issue, https://www.drupal.org/project/drupal/issues/2610858, which is attempting to improve error messaging about it, which may or may not impact Drush. Drush has had this question asked many, many times.

Score:0
us flag

agre with answer from @cilefen

this is my example for local project. try doing the same, bottom line - use 127.0.0.1 instead of localhost in file

settings.local.php

$databases['default']['default'] = array (
    'database' => 'yourproject_local',
    'username' => 'root',
    'password' => 'yourpassword',
    'prefix' => '',
    'host' => '127.0.0.1',
    'port' => '3306',
    'driver' => 'mysql',
);

$settings['trusted_host_patterns'] = array(
    '^subdomain\.test\.yourise\.local',
    '^yoursite\.dev\.local$',
    '^subdomain\.something\.yourhosting\.com$',
    '^example\.at$',
    '^www\.example\.at$',
);
apaderno avatar
us flag
If you agree with a given answer, wait you can up-vote answers and up-vote the existing answer. There is no need to add an answer just to repeat what already said, especially when the existing answer provides links that explain why it happens.
metalac avatar
us flag
of course, i've just added example how I use my settings.local.php file so maybe someone will use this snippet one day. I would like sometimes to get answers like that in my own questions.
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.