Answers.Body: <p>One other issue that causes drush not to list the CiviCRM commands:</p>
  
  <ul>
  <li>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.  
  
  <ul>
  <li>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.</li>
  </ul></li>
  </ul>
  
  <p><strong>Solution:</strong></p>
  
  <p>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.  </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-26T22:45:56.420Z
Answers.LastActivityDate: 2020-03-26T22:45:56.420Z
Answers.UserDisplayName: CommentUser_54346
Answers.Body: <p>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.</p>
  
  <p>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...</p>
  
  <p>can you try running your drush commands with a few extra params: </p>
  
  <pre><code>drush -u 1 -r /your/drupal/root civicrm-api job.process_mailing auth=0 -y -l yourdomain.org
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-19T08:30:17.523Z
Answers.Text: Can you explain the "job.process_mailing" part of these parameters? I'm still having this problem.
Answers.UserDisplayName: Christia
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-05T16:31:51.563Z
Answers.Text: 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.
Answers.UserDisplayName: freeform.steph
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-27T15:28:50.683Z
Answers.LastActivityDate: 2017-04-27T15:28:50.683Z
Answers.UserDisplayName: Xavier
Answers.Body: <p>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 <code>civicrm.settings.php</code> file, changing <code>localhost</code> to <code>127.0.0.1</code>. </p>
  
  <p><code>drush status</code> showed that the hostname was 127.0.0.1:</p>
  
  <pre><code>Database hostname               :  127.0.0.1
  </code></pre>
  
  <p>E.G.: </p>
  
  <pre><code>if (!defined('CIVICRM_UF_DSN') &amp;&amp; CIVICRM_UF !== 'UnitTests') {
    define( 'CIVICRM_UF_DSN'           , 'mysql://user:password@127.0.01/drupal?new_link=true');
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>if (!defined('CIVICRM_DSN')) {
    if (CIVICRM_UF === 'UnitTests' &amp;&amp; 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');
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-29T18:24:16.057Z
Answers.LastActivityDate: 2017-11-29T20:01:35.137Z
Answers.LastEditDate: 2017-11-29T20:01:35.137Z
Answers.UserDisplayName: Christia
Body: <p>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 <code>max_allowed_packets = 500M</code>.</p>
  
  <p>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:
  <code>drush fl</code>
  <code>drush cc all</code>
  <code>drush en some_module</code></p>
  
  <p>An example of drush commands that do work:
  <code>drush pm-list</code>
  <code>drush pm-info some_module</code>
  <code>drush dl some_module</code></p>
  
  <pre><code>&lt;p&gt;Initialization Error&lt;/p&gt;&lt;p&gt;&lt;pre&gt;Array
  (
      [callback] =&amp;gt; Array
          (
              [0] =&amp;gt; CRM_Core_Error
              [1] =&amp;gt; simpleHandler
          )
  
      [code] =&amp;gt; -24
      [message] =&amp;gt; DB Error: connect failed
      [mode] =&amp;gt; 16
      [debug_info] =&amp;gt;  [nativecode=No such file or directory]
      [type] =&amp;gt; DB_Error
      [user_info] =&amp;gt;  [nativecode=No such file or directory]
      [to_string] =&amp;gt; [db_error: message=&amp;quot;DB Error: connect failed&amp;quot; code=-24 mode=callback callback=CRM_Core_Error::simpleHandler prefix=&amp;quot;&amp;quot; info=&amp;quot; [nativecode=No such file or directory]&amp;quot;]
  )
  &lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Initialization Error&lt;/p&gt;&lt;p&gt;&lt;pre&gt;Array
  (
      [callback] =&amp;gt; Array
          (
              [0] =&amp;gt; CRM_Core_Error
              [1] =&amp;gt; simpleHandler
          )
  
      [code] =&amp;gt; -24
      [message] =&amp;gt; DB Error: connect failed
      [mode] =&amp;gt; 16
      [debug_info] =&amp;gt;  [nativecode=No such file or directory]
      [type] =&amp;gt; DB_Error
      [user_info] =&amp;gt;  [nativecode=No such file or directory]
      [to_string] =&amp;gt; [db_error: message=&amp;quot;DB Error: connect failed&amp;quot; code=-24 mode=callback callback=CRM_Core_Error::simpleHandler prefix=&amp;quot;&amp;quot; info=&amp;quot; [nativecode=No such file or directory]&amp;quot;]
  )
  &lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;Drush command terminated abnormally due to an unrecoverable error. 
  </code></pre>
  
  <p>My production and test environments do not throw this error, only the local ones.</p>
  
  <p>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.</p>
  
  <pre><code> 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 
  </code></pre>
  
  <p>This is installed locally on a Mac OSX 10.12.5, Drupal 7.54 running with AMPPS.</p>
  
  <p>Edit: AMPPS runs on TCP port 80 by default. I've tried changing the base URL in civicrm.settings.php to <code>http://localhost:80/[myprojectroot]</code> to no avail.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-26T20:53:47.347Z
Comments.Text: Are you saying some drush commands work and some don't? Post some examples? What directory are you in when you run this? Do you have a drushrc.php?
Comments.UserDisplayName: KarinG - Semper IT
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-26T23:35:07.813Z
Comments.Text: I updated my post with more info. I do not have a drushrc.php.
Comments.UserDisplayName: Christia
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-27T05:30:53.617Z
Comments.Text: See https://forum.civicrm.org/index.php?topic=33303.0
Comments.UserDisplayName: JorgeeFG
Tags: <drupal>
Title: Initialization Error on certain drush commands, related to CiviCRM
ThreadText: # Initialization Error on certain drush commands, related to CiviCRM
  
  (Asked by: username_0 on 2017-04-26)
  
  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
  Initialization ErrorArray
  (
      [callback] => Array
          (
              [0] => CRM_Core_Error
              [1] => simpleHandler
          )
  
      [code] => -24
      [message] => DB Error: connect failed
      [mode] => 16
      [debug_info] =>  [nativecode=No such file or directory]
      [type] => DB_Error
      [user_info] =>  [nativecode=No such file or directory]
      [to_string] => [db_error: message="DB Error: connect failed" code=-24 mode=callback callback=CRM_Core_Error::simpleHandler prefix="" info=" [nativecode=No such file or directory]"]
  )
  Initialization ErrorArray
  (
      [callback] => Array
          (
              [0] => CRM_Core_Error
              [1] => simpleHandler
          )
  
      [code] => -24
      [message] => DB Error: connect failed
      [mode] => 16
      [debug_info] =>  [nativecode=No such file or directory]
      [type] => DB_Error
      [user_info] =>  [nativecode=No such file or directory]
      [to_string] => [db_error: message="DB Error: connect failed" code=-24 mode=callback callback=CRM_Core_Error::simpleHandler prefix="" info=" [nativecode=No such file or directory]"]
  )
  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.
  
  **Tags:** drupal
  
  > **Comments:**
  > **username_1**: Are you saying some drush commands work and some don't? Post some examples? What directory are you in when you run this? Do you have a drushrc.php?  
  > **username_0**: I updated my post with more info. I do not have a drushrc.php.  
  > **username_2**: See https://forum.civicrm.org/index.php?topic=33303.0  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2020-03-26. Score: 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.
  
  
  ---
  
  ### Answer by username_4 on 2017-04-27. Score: 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
  
  > **Comments:**
  > **username_0**: Can you explain the "job.process_mailing" part of these parameters? I'm still having this problem.  
  > **username_5**: 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.  
  
  ---
  
  ### Answer by username_0 on 2017-11-29. Score: 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');
    }
  }
  
  
  ---
  
  