1

I'm having trouble connecting to my databases. It worked a few days ago but can't seem to figure why it doesn't work now. It's a D8-site. Drush version is 8.1.12.

I've double-checked both the alias-file and settings.php-files (both on server & local) and database settings all appear correct. My local site runs on Mamp 4.1.1. and network access is allowed.

Here's the error I get when running sql-sync drush sql-sync @local @dev. Rsync works fine.

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

And here's the aliases.drushrc.php (my local copy of course includes credentials:))

<?php

/* Tambourhinoceros Site */

$aliases["local"] = array (
 'root' => '', // local path
 'uri' => 'local.tambourhinoceros.net',  // local uri
 'path-aliases' =>
 array (
   '%dump-dir' => '/tmp',
   '%drush' => '/usr/local/bin',
   '%site' => 'sites/default',
 ),
 'remote-user' => 'tamb_dev', 
 'ssh-options' => '-T',
 'databases' =>
 array (
   'default' =>
   array (
     'default' =>
     array (
        'database' => '', // local database 
        'username' => '', // local database user
        'password' => '', // local database pw
        'host' => 'localhost',
        'port' => '8889',
        'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
        'driver' => 'mysql',
        'prefix' => '',
      ),
    ),
  ),
);

$aliases["dev"] = array (
  'root' => '', // remote path
  'uri' => 'drupal-85630-297475.cloudwaysapps.com', // remote uri
  'path-aliases' =>
  array (
  ),
  'remote-host' => '', remote IP
  'remote-user' => '', remote User
  'command-specific' =>
 array (
   'rsync' =>
   array (
     'mode' => 'rlptzO',
     'verbose' => true,
     'no-perms' => true,
   ),
 ),
 'databases' =>
 array (
   'default' =>
   array (
     'default' =>
     array (
        'database' => '', remote database
        'username' => '', remote  user
        'password' => '', remote pw
        'host' => 'localhost',
        'port' => '',
        'driver' => 'mysql',
        'prefix' => '',
      ),
    ),
  ),
)
?>
10
  • 1
    Is it this? drupal.stackexchange.com/questions/186446/…
    – Clive
    Commented Jul 25, 2017 at 15:44
  • How do I check if it is? I'm not sure what the commands used in that post does... Sorry for being a noob:) Commented Jul 25, 2017 at 16:10
  • Please post the command you typed.
    – mona lisa
    Commented Jul 25, 2017 at 22:05
  • Thanks for pitching in @cilefen. Original question is updated to include the command. Commented Jul 26, 2017 at 6:41
  • What are the relevant drush site alias configurations?
    – mona lisa
    Commented Jul 26, 2017 at 17:05

3 Answers 3

1

On your local connection, try adding "unix_socket" option and point to your local mysql socket.

$databases['default']['default'] = array (
  'database' => '',
  'username' => '',
  'password' => '',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
  'unix_socket' => '/var/mysql/mysql.sock',
);

More complete steps to debugging: https://drupal.stackexchange.com/a/174128/25221

4
  • Sorry, didn't fix it either (using /Applications/MAMP/tmp/mysql/mysql.sock) Commented Aug 3, 2017 at 21:01
  • 1
    Ah well, maybe some of the additional steps for determining the socket in this answer will help. drupal.stackexchange.com/a/174128/25221
    – daggerhart
    Commented Aug 4, 2017 at 13:47
  • Thanks @daggerhart. Everything except #5 works. But when running "mysql --socket=/var/mysql/mysql.sock" I get "ysql --socket=/var/mysql/mysql.sock ERROR 1045 (28000): Access denied for user 'kristofferrom'@'localhost' (using password: NO)". The user kristofferrom is my user on my local OS X and the user that MAMP defaults to. Any ideas? Commented Aug 4, 2017 at 20:38
  • 1
    That means you're reaching mysql, but not authenticating with it. You need to pass in info for your mysql user. For example: mysql -u root -p --socket=/var/mysql/mysql.sock then provide your root password when prompted.
    – daggerhart
    Commented Aug 6, 2017 at 3:44
1

It will be Solved by adding

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

to the drush command.

1
  • Nope, any way to debug why it's not working? Commented Aug 3, 2017 at 15:07
1

Solved. And as usual the issue turned out to be much smaller and simple than I thought...

My local path was missing the "/web" segment in the end. After adding it both rsync and sql-sync works!

Thanks for all the input people.

1
  • Where did you find the "/web" segment? In settings.php?
    – DamianFox
    Commented Mar 31, 2020 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.