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 sql-connect Unable to load class Drush\Sql\Sql #2721

Closed
richhorn opened this issue Apr 24, 2017 · 6 comments
Closed

drush sql-connect Unable to load class Drush\Sql\Sql #2721

richhorn opened this issue Apr 24, 2017 · 6 comments

Comments

@richhorn
Copy link

Ubuntu 16.04 localhost Drush 8.1.10 installed via composer as per the recommended route. Drupal 8.3

Drush runs and completes some tasks. eg

drush status

PHP executable : /usr/bin/php
PHP configuration : /etc/php/7.1/cli/php.ini
PHP OS : Linux
Drush script : /home/rich/vendor/drush/drush/drush.php
Drush version : 8.1.10
Drush temp directory : /tmp
Drush configuration :
Drush alias files :

However when I try any mysql/database-related commands I get errors

Usually like;

drush up

Command pm-update needs a higher bootstrap level to run - you will need to invoke drush from a more functional Drupal environment to run this command.
[error] The drush command 'up' could not be executed.

Or this one;

drush sql-connect

Unable to load class Drush\Sql\Sql [error]
Drush\Sql\SqlException: Unable to find a matching SQL Class. Drush cannot find your database connection details. in /home/rich/vendor/drush/drush/commands/sql/sql.drush.inc:541 [error]
Stack trace:
#0 /home/rich/vendor/drush/drush/commands/sql/sql.drush.inc(221): drush_sql_get_class()
#1 /home/rich/vendor/drush/drush/includes/command.inc(422): drush_sql_connect()
#2 /home/rich/vendor/drush/drush/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
#3 /home/rich/vendor/drush/drush/includes/command.inc(199): drush_command()
#4 /home/rich/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
#5 /home/rich/vendor/drush/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#6 /home/rich/vendor/drush/drush/drush.php(12): drush_main()
#7 {main}

My settings.php

$databases['default']['default'] = array (
'database' => 'drupal8-test1',
'username' => '',
'password' => '',
'prefix' => '',
'host' => '127.0.0.1',
'port' => '3306',
'namespace' => 'Drupal\Core\Database\Driver\mysql',
'driver' => 'mysql', );

PATH in .bashrc

export PATH=$HOME/.config/composer/vendor/bin:$PATH export PATH=/bin:/usr/local/bin:/usr/local/mysql/bin:$PATH

Seems correct to me ...?

I have tried Forcing 127.0.0.1 instead of localhost.
I am running drush from drupal root directory.
I would greatly appreciate any suggestions as to where to go next with this. :)
Thanks for looking.

@weitzman
Copy link
Member

Add --debug and you will see the actual shell commands that are run. See if those fail and fix if needed.

@richhorn
Copy link
Author

Thank you, Moshe, for your prompt reply.
:)
I have done as you suggested, but am unsure now where to go with the outputs.
Please would you advise?

So ...

drush up --debug

Using the Drush script found at /home/rich/vendor/drush/drush/drush.launcher using pcntl_exec
Cache HIT cid: 8.1.10-commandfiles-0-fcef2bb3879f94f27262252d9ac29def [0.01 sec, 870.66 KB] [debug]
Bootstrap to phase 0. [0.08 sec, 2.79 MB] [bootstrap]
Bootstrap to phase 6. [0.08 sec, 2.79 MB] [bootstrap]
Command pm-update needs a higher bootstrap level to run - you will need to invoke drush from a more functional Drupal environment to run this command. [0.08 sec, 2.8 MB] [error]
The drush command 'up' could not be executed. [0.08 sec, 2.8 MB]

and

drush sql-cli --debug

Using the Drush script found at /home/rich/vendor/drush/drush/drush.launcher using pcntl_exec
Cache HIT cid: 8.1.10-commandfiles-0-fcef2bb3879f94f27262252d9ac29def [0.01 sec, 870.66 KB] [debug]
Bootstrap to phase 0. [0.08 sec, 2.79 MB] [bootstrap]
Bootstrap to phase -1. [0.09 sec, 2.79 MB] [bootstrap]
Found command: sql-cli (commandfile=sql) [0.09 sec, 2.8 MB] [bootstrap]
Calling hook drush_sql_cli [0.09 sec, 2.92 MB] [debug]
Unable to load class Drush\Sql\Sql [0.09 sec, 2.93 MB] [error]
Drush\Sql\SqlException: Unable to find a matching SQL Class. Drush cannot find your database connection details. in /home/rich/vendor/drush/drush/commands/sql/sql.drush.inc:541 [error]
Stack trace:
#0 /home/rich/vendor/drush/drush/commands/sql/sql.drush.inc(446): drush_sql_get_class()
#1 /home/rich/vendor/drush/drush/includes/command.inc(422): drush_sql_cli()
#2 /home/rich/vendor/drush/drush/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
#3 /home/rich/vendor/drush/drush/includes/command.inc(199): drush_command()
#4 /home/rich/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
#5 /home/rich/vendor/drush/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#6 /home/rich/vendor/drush/drush/drush.php(12): drush_main()
#7 {main} [0.09 sec, 2.94 MB]
Command dispatch complete [0.09 sec, 2.88 MB]

and

drush sql-connect --debug

Using the Drush script found at /home/rich/vendor/drush/drush/drush.launcher using pcntl_exec
Cache HIT cid: 8.1.10-commandfiles-0-fcef2bb3879f94f27262252d9ac29def [0.01 sec, 870.66 KB] [debug]
Bootstrap to phase 0. [0.08 sec, 2.79 MB] [bootstrap]
Bootstrap to phase -1. [0.08 sec, 2.79 MB] [bootstrap]
Found command: sql-connect (commandfile=sql) [0.08 sec, 2.8 MB] [bootstrap]
Calling hook drush_sql_connect [0.09 sec, 2.92 MB] [debug]
Unable to load class Drush\Sql\Sql [0.09 sec, 2.93 MB] [error]
Drush\Sql\SqlException: Unable to find a matching SQL Class. Drush cannot find your database connection details. in /home/rich/vendor/drush/drush/commands/sql/sql.drush.inc:541 [error]
Stack trace:
#0 /home/rich/vendor/drush/drush/commands/sql/sql.drush.inc(221): drush_sql_get_class()
#1 /home/rich/vendor/drush/drush/includes/command.inc(422): drush_sql_connect()
#2 /home/rich/vendor/drush/drush/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
#3 /home/rich/vendor/drush/drush/includes/command.inc(199): drush_command()
#4 /home/rich/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
#5 /home/rich/vendor/drush/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#6 /home/rich/vendor/drush/drush/drush.php(12): drush_main()
#7 {main} [0.09 sec, 2.94 MB]
Command dispatch complete [0.09 sec, 2.88 MB]

@richhorn
Copy link
Author

Solved by adding

--root=/full/path/to/your/webroot

to the drush command.

Thanks all :)

@gzveri
Copy link

gzveri commented May 1, 2018

drush sql-dump --root=c:/mysites/htdocs/mylocalsite/

worked fine, thanks for the hint

@n8thanael
Copy link

n8thanael commented May 26, 2020

I encountered this error while migrating a Acquia Dev Desktop build into an AWS environment using a Bitnami AMI. Similar to how DevDesktop pulls the settings['default']['default'] mysql configuration from:

if (isset($_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR']) && file_exists($_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] . '/loc_mysite-enviornment_dd.inc')) { require $_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] . '/loc_mysite-enviornment_dd.inc'; }

I enabled a similar strategy by pulling the path to the settings directory (which is the home directory) directly into the settings.php file via php require(). $_SERVER['BITNAMI_DRUPAL_SETTINGS_DIR'] would dynamically pull in the proper settings in my Apache2 vhosts_httpd.config files:

elseif (isset($_SERVER['BITNAMI_DRUPAL_SETTINGS_DIR']) && file_exists($_SERVER['BITNAMI_DRUPAL_SETTINGS_DIR'])) { require $_SERVER['BITNAMI_DRUPAL_SETTINGS_DIR']; }

Some how drush still won't recognize the settings using drush sql commands ... even though other commands such as drush archive-dump work correctly. I couldn't discover why drush does this, but the solution was simply to remove the require() and have the database settings in the settings.php file.

@wturrell
Copy link

wturrell commented Feb 1, 2021

@n8thanael the issue (for me anyway, when trying to run Drush on local dev sites) is that Acquia's conditional only runs when serving web pages, not via the Drush CLI, because when you use the CLI, $_SERVER doesn't exist…

You can work around it by adding this line outside (above) the <DDSETTINGS> block.

$_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] = '/Users/[your-username-here]/.acquia/DevDesktop/DrupalSettings';

(That's an example for macOS users.)

It's enough to trick the rest of Dev Desktop's code into looking in the correct place without having to rewrite or duplicate it.

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

5 participants