Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drush si should not continue if it can't connect to the database; outputs misleading error #511

Closed
webchick opened this issue Mar 7, 2014 · 16 comments

Comments

@webchick
Copy link

webchick commented Mar 7, 2014

In yet another fabulous display of PEBCAK, today I attempted to use drush si whilst Acquia Dev Desktop was turned off, so there was no MySQL database / Apache process to serve drush's request. drush si of course failed. However, rather than Drush bailing out when it couldn't find the database, it proceeded along anyway, so I ended up getting a Drupal\Core\Installer\Exception\AlreadyInstalledException which sent me down a few rabbit holes before I finally gave up and resigned myself to a manual install through the UI and thereby instantly realized my mistake. :P

Suggestion would be:

$ drush si --account-pass=admin -y
You are about to empty any Config directories and CREATE the '8x' database. Do you want to continue? (y/n): y
Warning: Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (61)
# STOP. FAIL HERE. DO NOT CONTINUE. IT IS POINTLESS. LIFE IS MEANINGLESS. AND SO ON.
Starting Drupal installation. This takes a few seconds ...           [ok]
WD php: Drupal\Core\Installer\Exception\AlreadyInstalledException:   [error]
[5K of HTML barf]
@weitzman
Copy link
Member

Not sure the best way to catch this. I'll think about it.

Meanwhile, [5K of HTML barf] is a problem for me too. Drupal should not assume that it is serving an HTML page.

@mikeryan776
Copy link

+1 - same thing happened to me today, but without the "Can't connect to MySQL server" error to clue me in, so I blamed my fresh pull of core and spun my wheels trying to find which recent commit to blame.

An underlying issue here is that AlreadyInstalledException is thrown from various places, it would be helpful if core provided a specific hint at each place as to why it thinks Drupal is already installed...

@mikeryan776
Copy link

Core issue: https://www.drupal.org/node/2459671

@weitzman
Copy link
Member

The first time Drush tries to connect to Db we are checking if the target DB exists. The way we do that currently makes it hard to distinguish between DB needing to be created and mysql being unavailable. Needs a little refactor.

@tbfisher
Copy link

tbfisher commented Aug 1, 2015

I'm confused...

$ drush si
You are about to DROP all tables in your 'example2' database. Do you want to continue? (y/n): y
Starting Drupal installation. This takes a while. Consider using the [ok]
--notify global option.
exception 'Drupal\Core\Installer\Exception\AlreadyInstalledException'[error]
with message '<ul>
<li>To start over, you must empty your existing database and copy
<em>default.settings.php</em> over <em>settings.php</em>.</li>

@frankcarey
Copy link

Yes, I get the same error after trying to re-install with "drush si --writable"

This may be because setting.php was being overridden from a previous install attempt

@weitzman
Copy link
Member

Whats --writable? Thats not in core Drush.

@RoSk0
Copy link
Contributor

RoSk0 commented Oct 27, 2017

The same issue still happens when drush fails to delete all tables(sql-drop) before si. In my case this happen because there was way too many tables left after simpletest(~7.2k) and PostgreSQL was running out of memory to wrap transaction

@joachim-n
Copy link
Contributor

Seeing this with Drush 10:


 You are about to:
 * Create a sites/default/settings.php file
 * CREATE the 'drupal-foobar' database.

 Do you want to continue? (yes/no) [yes]:
 >

 [warning] Failed to drop or create the database. Do it yourself before installing. ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (61)

 [notice] Starting Drupal installation. This takes a while.
 [notice] Performed install task: install_select_language
 [notice] Performed install task: install_select_profile
 [notice] Performed install task: install_load_profile
 [notice] Performed install task: install_verify_requirements

In install.core.inc line 967:

  Resolve all issues below to continue the installation. For help configuring your database server, see the <a hre
  f="https://www.drupal.org/docs/8/install">installation handbook</a>, or contact your hosting provider.<div class
  ="item-list"><ul><li>Failed to connect to your database server. The server reports the following message: <em cl
  ass="placeholder">SQLSTATE[HY000] [2002] Connection refused</em>.<ul><li>Is the database server running?</li><li
  >Does the database exist or does the database user have sufficient privileges to create the database?</li><li>Ha
  ve you entered the correct database name?</li><li>Have you entered the correct username and password?</li><li>Ha
  ve you entered the correct database hostname and port number?</li></ul></li></ul></div>


site:install [--db-url DB-URL] [--db-prefix DB-PREFIX] [--db-su DB-SU] [--db-su-pw DB-SU-PW] [--account-name [ACCOUNT-NAME]] [--account-mail [ACCOUNT-MAIL]] [--site-mail [SITE-MAIL]] [--account-pass ACCOUNT-PASS] [--locale [LOCALE]] [--site-name [SITE-NAME]] [--site-pass SITE-PASS] [--sites-subdir SITES-SUBDIR] [--config-dir CONFIG-DIR] [--existing-config] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-d|--debug] [-y|--yes] [--no] [--remote-host REMOTE-HOST] [--remote-user REMOTE-USER] [-r|--root ROOT] [-l|--uri URI] [--simulate] [--pipe] [-D|--define DEFINE] [--notify [NOTIFY]] [--druplicon] [--xh-link XH-LINK] [--] <command> [<profile>]...

@weitzman
Copy link
Member

weitzman commented Feb 1, 2021

Yeah, that’s much better, IMO we ca close this.

@weitzman weitzman closed this as completed Feb 1, 2021
@joachim-n
Copy link
Contributor

It's better, but it's still needlessly doing all this:

 [notice] Starting Drupal installation. This takes a while.
 [notice] Performed install task: install_select_language
 [notice] Performed install task: install_select_profile
 [notice] Performed install task: install_load_profile
 [notice] Performed install task: install_verify_requirements

@weitzman
Copy link
Member

weitzman commented Feb 1, 2021

That’s new logging in Drush 10 that I've found helpful. Installer errors are often hard to debug. This helps a bunch. It also helps identify why Drupal's installer is so slow. Otherwise we hwave a prompt that says nothing for 30 seconds.

I suppose they could be info level instead of notice level if these messages bothered more people.

@joachim-n
Copy link
Contributor

What I mean is (to quote webchick from years ago) this:

 [warning] Failed to drop or create the database. Do it yourself before installing. ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (61)

# STOP. FAIL HERE. DO NOT CONTINUE. IT IS POINTLESS. LIFE IS MEANINGLESS. AND SO ON.

 [notice] Starting Drupal installation. This takes a while.
 [notice] Performed install task: install_select_language
 [notice] Performed install task: install_select_profile
 [notice] Performed install task: install_load_profile
 [notice] Performed install task: install_verify_requirements

@weitzman
Copy link
Member

weitzman commented Feb 1, 2021

Ah, I see. Basically, we don't know if install will succeed at that point. All we know is that we failed to drop existing tables. Often that happens because there is no mysql on user's PATH (common with Docker). So now Drush considers this not a fatal error, and proceeds with a 'Drop them yourself' message. I know the error text says 'Connection refused' but we generally don't parse and rely on CLI error text (unlike PHP Exception type which is more explicit).

@weitzman
Copy link
Member

weitzman commented Feb 1, 2021

I forgot to say that you can run all but sql:* commands without a mysql client nowadays, including site:install. The bootstrap uses PDO instead of mysql

@weitzman
Copy link
Member

weitzman commented Feb 1, 2021

If someone wants to work on quitting earlier, $sql->getProcess()->getErrorOutput() gives ERROR 2002 (HY000): Can't connect to MySQL server on '192.168.3.99' (36) for me. Add a check for that here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants