Where does drush look for the path of the mysql socket (on MAMP)? After upgrading from drush 6.5.0 to 8.0.1-dev through brew, the drush terminal command returns the popular 


  'PDOException: SQLSTATE[HY000] [2002]' error.


The only way to make it work is to add the unix_socket line to my Drupal settings.php files for all my projects:

$databases = array (
  'default' =&gt;
  array (
    'default' =&gt;
    array (
      'database' =&gt; 'site',
      'username' =&gt; 'user',
      'password' =&gt; 'pass',
      'host' =&gt; 'localhost',
      'port' =&gt; '',
      'driver' =&gt; 'mysql',
      'prefix' =&gt; '',
      'unix_socket' =&gt; '/Applications/MAMP/tmp/mysql/mysql.sock',
    ),
  ),
);


Even if I use /var/mysql/mysql.sock, it will work, because I have a symlink up:

lrwxr-xr-x  1 root  wheel    39B Mar 11  2015 /var/mysql/mysql.sock -&gt; /Applications/MAMP/tmp/mysql/mysql.sock


But that is exactly the thing I don't understand. And I would like to configure it at one point so I don't have to edit all the current and upcoming project's settings.php files.

So my question is: Where does drush look for the path of the mysql socket (on MAMP)?

If it's through the php.ini, it should be correct too (/Applications/MAMP/bin/php/php5.6.10/conf/php.ini):

mysql.default_socket = /Applications/MAMP/tmp/mysql/mysql.sock


Currently, my .bash_profile contains no alias or export related to this issue because it worked fine with my previous drush installation.
First of all, check which php and php.ini file is used by drush:

$ drush status --full
 Site URI                        :  http://default                                                                                                          
 Database driver                 :  mysql                                                                                                                   
 Database hostname               :  localhost                                                                                                               
 Database username               :  root                                                                                                                    
 Database name                   :  drupal7                                                                                                                  
 Drupal bootstrap                :  Successful                                                                                                              
 Drupal user                     :                                                                                                                          
 PHP executable                  :  /usr/local/opt/php56/bin/php                                                                                            
 PHP configuration               :  /usr/local/etc/php/5.6/php.ini  


Then edit its default MySQL socket name for local db connects:

pdo_mysql.default_socket=/path/to/mysql.sock


as by default it points to /tmp/mysql.sock unless PHP was configured with different (--with-mysql-sock).

Check by:

$ php -i | grep ^pdo_mysql.default_socket
pdo_mysql.default_socket =&gt; /tmp/mysql.sock =&gt; /tmp/mysql.sock


So probably that's why /var/mysql/mysql.sock didn't work, as it was looking for /tmp/mysql.sock instead.

Then the symbolic link should work as expected.

If drush is using wrong instance of PHP, then add it into PATH (as you did) or specify with --php=&lt;/path/to/file&gt;, so the right php.ini would be loaded.

Alternatively specify unix_socket in your settings file (as you already did).