drush-ops / drush

Drush is a command-line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those who spend their working hours hacking away at the command prompt.
https://www.drush.org
2.34k stars 1.08k forks source link

'drush si' ignores unix-socket specification; attempts, & FAILs, to use non-existent & un-specified '/tmp/mysql.sock' #6170

Open pgnd opened 4 days ago

pgnd commented 4 days ago

i can connect to a MariaDB instance from shell

    mariadb -h localhost -u ${DB_USR} --password="${DB_USR_PWD}" -e "\s" | grep -E "^UNIX|^Connection|^Server"
        Connection id:          43
        Server:                 MariaDB
        Server version:         11.4.5-MariaDB-log MariaDB Server
        Connection:             Localhost via UNIX socket
        Server characterset:    utf8mb4
        UNIX socket:            /run/mariadb/mariadb.sock

where

    mariadb-show

        +--------------------+
        |     Databases      |
        +--------------------+
        | information_schema |
        | mysql              |
        | db_drupal          |
        | sys                |
        +--------------------+

with

    drush status
        Drupal version : 11.0.9
        Site URI       : http://default
        PHP binary     : /usr/bin/php
        PHP config     : /usr/local/etc/php8/php.ini
        PHP OS         : Linux
        PHP version    : 8.4.1
        Drush script   : /svr/drupal.app/vendor/bin/drush.php
        Drush version  : 13.3.3.0
        Drush temp     : /tmp
        Drush configs  : /svr/drupal.app/vendor/drush/drush/drush.ym
                         l
        Drupal root    : /svr/drupal.app/web
        Site path      : sites/default

site install

    drush -vvv site-install standard -y \
     --site-name="${SITE_NAME}" \
     --sites-subdir="${SITE_NAME}" \
     --db-url=mysql://"${DB_USR}":\"${DB_USR_PWD}\"@localhost/${DB_NAME}?unix_socket=/run/mariadb/mariadb.sock \
      --db-su=${SU_USR} \
      --db-su-pw=${SU_PW} \
      --site-mail="${SITE_EMAIL}" \
      --account-mail="${ADMIN_EMAIL}" \
      --account-name=${ADMIN_USR} \
      --account-pass=$(ADMIN_PWD) \
      --locale=en \
      install_configure_form.enable_update_status_emails=NULL

fails with

 [preflight] Drush disables Xdebug by default. To override this, see https://www.drush.org/latest/commands/#xdebug
 [preflight] Config paths: /svr/drupal.app/vendor/drush/drush/drush.yml
 [preflight] Alias paths: /svr/drupal.app/web/drush/sites,/svr/drupal.app/drush/sites
 [preflight] Commandfile search paths: /svr/drupal.app/vendor/drush/drush/src
 [info] Starting bootstrap to root [0.52 sec, 5.17 MB]
 [info] Drush bootstrap phase 1 [0.52 sec, 5.17 MB]
 [info] Try to validate bootstrap phase 1 [0.52 sec, 5.17 MB]
 [info] Try to validate bootstrap phase 1 [0.52 sec, 5.17 MB]
 [info] Try to bootstrap at phase 1 [0.52 sec, 5.17 MB]
 [info] Drush bootstrap phase: bootstrapDrupalRoot() [0.52 sec, 5.17 MB]
 [info] Change working directory to /svr/drupal.app/web [0.52 sec, 5.17 MB]
 [info] Initialized Drupal 11.0.9 root directory at /svr/drupal.app/web [0.52 sec, 5.24 MB]
 [warning] Only lowercase sites-subdir are valid. Switching to mysite. [0.53 sec, 5.5 MB]
 [info] Drush bootstrap phase: bootstrapDrupalSite() [0.54 sec, 5.79 MB]
 [debug] Could not find a Drush config file at sites/mysite/drush.yml. [0.54 sec, 5.85 MB]
 [info] Initialized Drupal site mysite at sites/mysite [0.54 sec, 5.85 MB]
 [info] Drush bootstrap phase: bootstrapDrupalConfiguration() [0.54 sec, 5.85 MB]
 [info] sql:query: SELECT VERSION();" [0.57 sec, 6.47 MB]
 [info] Executing: mysql --defaults-file=/tmp/drush_u58n5rfmhn5m8G0UBoR --database=db_drupal --host=localhost --silent -A < /tmp/drush_5ruauobd9frs36cVaVm [0.58 sec, 6.67 MB]
 [info] sql:query: SELECT VERSION();" [0.59 sec, 6.73 MB]
 [info] Executing: mysql --defaults-file=/tmp/drush_js4nr07j9iibeAGADCO --database=db_drupal --host=localhost --silent -A < /tmp/drush_cbmqk6tvb74c84Yp82w [0.59 sec, 6.73 MB]
 [info] Executing: command -v mysql [0.59 sec, 6.74 MB]
 [info] sql:query: SELECT 1; [0.6 sec, 6.74 MB]
 [info] Executing: mysql --defaults-file=/tmp/drush_7dcvgie0vfj4eSUCA4G --database=db_drupal --host=localhost --silent -A < /tmp/drush_kto9d1kkqi3c4y3vIDl [0.6 sec, 6.74 MB]
 You are about to:
 * CREATE the 'db_drupal' database.

 // Do you want to continue?: yes.

 [info] Sites directory sites/mysite already exists - proceeding. [0.61 sec, 6.87 MB]
 [info] sql:query: SELECT 1; [0.61 sec, 6.87 MB]
 [info] Executing: mysql --defaults-file=/tmp/drush_6njgp7uv8vqh0K3UCb5 --database=db_drupal --host=localhost --silent -A < /tmp/drush_rfcpkvqa6dhi6yAetpr [0.61 sec, 6.87 MB]
 [info] sql:query: DROP DATABASE IF EXISTS `db_drupal`; CREATE DATABASE `db_drupal` /*!40100 DEFAULT CHARACTER SET utf8 */; DROP USER IF EXISTS 'db_drupal_user'@'localhost'; CREATE USER 'db_drupal_user'@'localhost' IDENTIFIED WITH mysql_native_password; ALTER USER 'db_drupal_user'@'localhost' IDENTIFIED BY '"xxxxxxxxxxxx"'; GRANT ALL PRIVILEGES ON `db_drupal`.* TO 'db_drupal_user'@'localhost'; FLUSH PRIVILEGES; [0.62 sec, 6.87 MB]
 [info] Executing: mysql --defaults-file=/tmp/drush_cokp5sha10lcaOZuHPt --database=information_schema --host=localhost --silent -A < /tmp/drush_0md0cpc46k8k73xwepc [0.62 sec, 6.87 MB]
 [warning] Failed to drop or create the database. Do it yourself before installing. mysql: Deprecated program name. It will be removed in a future release, use '/usr/local/mariadb-lts/bin/mariadb' instead
ERROR 2002 (HY000): Can't connect to local server through socket '/tmp/mysql.sock' (2)
 [0.62 sec, 6.87 MB]
 [info] sql:query: SELECT VERSION();" [0.63 sec, 6.93 MB]
 [info] Executing: mysql --defaults-file=/tmp/drush_pp8u8heolctlfxcwvGT --database=db_drupal --host=localhost --silent -A < /tmp/drush_3b5udmq68gp1e2kzOo3 [0.63 sec, 6.93 MB]
 [notice] Starting Drupal installation. This takes a while. [0.63 sec, 6.94 MB]
 [debug] Calling install_drupal(Composer\Autoload\ClassLoader, array, array) [0.64 sec, 7 MB]
 [notice] Performed install task: install_select_language [0.96 sec, 16.13 MB]
 [notice] Performed install task: install_select_profile [0.96 sec, 16.13 MB]
 [notice] Performed install task: install_load_profile [0.96 sec, 16.13 MB]
 [notice] Performed install task: install_verify_requirements [0.97 sec, 16.23 MB]

In SiteInstallCommands.php line 177:

  [Drupal\Core\Installer\Exception\InstallerException]
  Resolve all issues below to continue the installation. For help configuring
  your database server, see the installation handbook [1], or contact your
  hosting provider.
   * Failed to connect to your database server. The server reports the
     following message: /SQLSTATE[HY000] [2002] No such file or directory [Tip:
     Drupal was attempting to connect to the database server via a socket, but
     the socket file could not be found. A Unix socket file is used if you do
     not specify a host name or if you specify the special host name localhost.
     To connect via TCP/IP use an IP address (127.0.0.1 for IPv4) instead of
     "localhost". This message normally means that there is no MySQL server
     running on the system or that you are using an incorrect Unix socket file
     name when trying to connect to the server.] /.
      * Is the database server running?
      * Does the database exist or does the database user have sufficient
        privileges to create the database?
      * Have you entered the correct database name?
      * Have you entered the correct username and password?
      * Have you entered the correct database hostname and port number?
...

the issue appears to be wrong socket

ERROR 2002 (HY000): Can't connect to local server through socket '/tmp/mysql.sock' (2)

despite passing

--db-url=...?unix_socket=/run/mariadb/mariadb.sock

to drush si

i've no idea where that /tmp/mysql.sock originates.

here

php -v
    PHP 8.4.1 (cli) (built: Nov 20 2024 09:48:35) (NTS gcc x86_64)
    Copyright (c) The PHP Group
    Built by Remi's RPM repository <https://rpms.remirepo.net/> #StandWithUkraine
    Zend Engine v4.4.1, Copyright (c) Zend Technologies
        with Zend OPcache v8.4.1, Copyright (c), by Zend Technologies
        with Xdebug v3.4.0beta1, Copyright (c) 2002-2024, by Derick Rethans

php -i | grep -i \.default_socket
    mysqli.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock
    pdo_mysql.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock

our production MariadDB instance is explicity built with

   -DMARIADB_UNIX_ADDR=/run/mariadb/mariadb.sock \

so, by default

mariadb --help | grep ^socket
    socket                            /run/mariadb/mariadb.sock

and accepts only unix socket connections; TCP connection is disallowed by policy and build config.

what's the db-url string format to correctly pass the /run/mariadb/mariadb.sock to drush si?

weitzman commented 4 days ago

Looks like a dupe of https://github.com/drush-ops/drush/pull/5567

pgnd commented 4 days ago

@weitzman

which iiuc is a WONTFIX ?