1

I am getting the following error whenever I run certain drush commands, however, the CiviCRM seems to be working fine. I have ensured that my my.conf file is set to max_allowed_packets = 500M.

An example of drush commands that throw the error follow. Note, I am in the Drupal root, and all commands that generate the error do work unless they are designed to print information into the terminal that I need: drush fl drush cc all drush en some_module

An example of drush commands that do work: drush pm-list drush pm-info some_module drush dl some_module

<p>Initialization Error</p><p><pre>Array
(
    [callback] =&gt; Array
        (
            [0] =&gt; CRM_Core_Error
            [1] =&gt; simpleHandler
        )

    [code] =&gt; -24
    [message] =&gt; DB Error: connect failed
    [mode] =&gt; 16
    [debug_info] =&gt;  [nativecode=No such file or directory]
    [type] =&gt; DB_Error
    [user_info] =&gt;  [nativecode=No such file or directory]
    [to_string] =&gt; [db_error: message=&quot;DB Error: connect failed&quot; code=-24 mode=callback callback=CRM_Core_Error::simpleHandler prefix=&quot;&quot; info=&quot; [nativecode=No such file or directory]&quot;]
)
</pre></p><p></p><p>Initialization Error</p><p><pre>Array
(
    [callback] =&gt; Array
        (
            [0] =&gt; CRM_Core_Error
            [1] =&gt; simpleHandler
        )

    [code] =&gt; -24
    [message] =&gt; DB Error: connect failed
    [mode] =&gt; 16
    [debug_info] =&gt;  [nativecode=No such file or directory]
    [type] =&gt; DB_Error
    [user_info] =&gt;  [nativecode=No such file or directory]
    [to_string] =&gt; [db_error: message=&quot;DB Error: connect failed&quot; code=-24 mode=callback callback=CRM_Core_Error::simpleHandler prefix=&quot;&quot; info=&quot; [nativecode=No such file or directory]&quot;]
)
</pre></p><p></p>Drush command terminated abnormally due to an unrecoverable error. 

My production and test environments do not throw this error, only the local ones.

Here is a drush status. If this is a Drupal issue and not a CiviCRM issue, I can move it to Drupal but the error is distinctly about the CRM.

 Drupal version                  :  7.54                                             
 Site URI                        :  http://default                                   
 Database driver                 :  mysql                                            
 Database hostname               :  127.0.0.1                                        
 Database port                   :                                                   
 Database username               :  myuser                                            
 Database name                   :  drupal                                
 Database                        :  Connected                                        
 Drupal bootstrap                :  Successful                                       
 Drupal user                     :                                                   
 Default theme                   :  glazed                                           
 Administration theme            :  myadmintheme                                 
 PHP executable                  :  /usr/local/bin/php                               
 PHP configuration               :  /usr/local/etc/php/7.1/php.ini                   
 PHP OS                          :  Darwin                                           
 Drush script                    :  /usr/local/Cellar/drush/8.1.15/libexec/drush.php 
 Drush version                   :  8.1.15                                           
 Drush temp directory            :  /tmp                                             
 Drush configuration             :                                                   
 Drush alias files               :                                                   
 Install profile                 :  cms                                              
 Drupal root                     :  /Applications/AMPPS/www/myproject/docroot       
 Drupal Settings File            :  sites/default/settings.php                       
 Site path                       :  sites/default                                    
 File directory path             :  sites/default/files/                             
 Private file directory path     :  ../files-private                                 
 Temporary file directory path   :  /tmp 

This is installed locally on a Mac OSX 10.12.5, Drupal 7.54 running with AMPPS.

Edit: AMPPS runs on TCP port 80 by default. I've tried changing the base URL in civicrm.settings.php to http://localhost:80/[myprojectroot] to no avail.

1

It looks like the commands that do work (download for instance) do not need to access the database, but those that fail (enable) do need a complete working drupal setup.

It might be because of several reasons, either you have your config installed elsewhere than in sites/default, or you have a different php config for cli and apache, or you do not authenticate properly, or...

can you try running your drush commands with a few extra params:

drush -u 1 -r /your/drupal/root civicrm-api job.process_mailing auth=0 -y -l yourdomain.org
| improve this answer | |
  • Can you explain the "job.process_mailing" part of these parameters? I'm still having this problem. – Christia Nov 19 '17 at 8:30
  • We are running into this issue with CiviCRM 4.6.33, Drupal 7.59, and Drush 8.1.17. Tried running from a remote location using an alias, as well as from directly within the home directory Tried "localhost" & "127.0.0.1" Tried adding "--root=/path/to/webroot" to the command Drupal & CIviCRM running without issue We continue to have no issues with the native drush commands (including sql-dump), but any CiviCRM commands requiring DB fail to connect (eg. civicrm-sql-dump). We were successfully using these commands prior to upgrading to Drush 8 OR latest CiviCRM update, not sure which. – freeform.steph Jul 5 '18 at 16:31
1

Thanks for everyone that helped out! It set me on track to the solution, which was to edit the database credentials for Drupal and CiviCRM in the civicrm.settings.php file, changing localhost to 127.0.0.1.

drush status showed that the hostname was 127.0.0.1:

Database hostname               :  127.0.0.1

E.G.:

if (!defined('CIVICRM_UF_DSN') && CIVICRM_UF !== 'UnitTests') {
  define( 'CIVICRM_UF_DSN'           , 'mysql://user:password@127.0.01/drupal?new_link=true');
}

and

if (!defined('CIVICRM_DSN')) {
  if (CIVICRM_UF === 'UnitTests' && isset($GLOBALS['_CV']['TEST_DB_DSN'])) {
    define('CIVICRM_DSN', $GLOBALS['_CV']['TEST_DB_DSN']);
  }
  else {
    define('CIVICRM_DSN', 'mysql://user:password@127.0.0.1/civicrm?new_link=true');
  }
}
| improve this answer | |
1

One other issue that causes drush not to list the CiviCRM commands:

  • If the user has a my.cnf with the blank password value in the user profile directory in linux of the user that drush is running as, drush will not list the CiviCRM commands.
    • It appears drush may use the user defined in my.cnf first, and does not failover to the user defined in the sites/default settings files.

Solution:

When I either added the password back into my.cnf in the profile of the user running the drush command, or renamed the my.cnf file in the user profile directory to something else (since in my case I did not want the root user being able to automatically sign-in to mysql using the credentials in the my.cnf file), then drush worked correctly and listed the CiviCRM commands.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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