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' =>
  array (
    'default' =>
    array (
      'database' => 'site',
      'username' => 'user',
      'password' => 'pass',
      'host' => 'localhost',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
      'unix_socket' => '/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 -> /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.

closed as too broad by Krishna Mohan, Mołot, Shawn Conn, Scott Joudry, Chapabu Dec 18 '15 at 22:01

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


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:


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 => /tmp/mysql.sock => /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=</path/to/file>, so the right php.ini would be loaded.

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

  • 1
    probably /usr/local/etc/php/5.6/php.ini was used and indeed, pdo_mysql.default_socket was not even set there – Kevin Van Humbeeck Dec 16 '15 at 18:35
  • 1
    As well as drush status --full, check php -i and look for "Additional .ini files parsed" - these are a common place to override settings in your main php.ini. – Chris Burgess Dec 21 '15 at 19:36

Found the solution ...

drush status

shows the PHP executable path was the OSX native one, which was then symlinked to a PHP installed by brew

adding the following line to ~/.bash_profile

export PATH="/Applications/MAMP/bin/php/php5.6.10/bin:/Applications/MAMP/Library/bin:$PATH"

made drush look up into the correct php.ini file

but to me, it is still a mystery why the symlink

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

did not do the trick

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