I installed Drush for the first time (so it may be a configuration error) and I'm trying to update to the latest core version of Drupal.

Drush is giving me this error - I'm on an OSX box.

dev5:clientnamedirectory my.name$ drush pm-update projects drupal-7.25
<h1>Additional uncaught exception thrown while handling exception.</h1>

<h2>Original</h2><p>PDOException: SQLSTATE[HY000] [2002] No such file or directory in drupal_get_installed_schema_version() (line 155 of /Users/my.name/Sites/proface/includes/install.inc).</p>


<p>PDOException: SQLSTATE[HY000] [2002] No such file or directory in system_list() (line 165 of /Users/my.name/Sites/clientnamedirectory/includes/module.inc).</p><hr />

Drush command terminated abnormally due to an unrecoverable error.
  • 1
    Have you completed these steps? I know it may not be exactly your issue, but it may help.
    – Chapabu
    Commented Jan 3, 2012 at 15:05
  • Which version of drush are you using? There is issue that seem to be identical with yours: drupal.org/node/832472
    – F1234k
    Commented Jan 3, 2012 at 15:06
  • I'm using version drush-7.x-4.5 and drupal 7.9
    – FLY
    Commented Jan 3, 2012 at 15:15
  • added the steps that I followed to my question. Seams like similar staps you are sugessting @Chapabu
    – FLY
    Commented Jan 3, 2012 at 15:36
  • 1
    You have a PHP/MySQL connection problem (not Drupal related) - stackoverflow.com/questions/2412009/…
    – Clive
    Commented Jan 9, 2014 at 18:22

12 Answers 12


In your database configuration in the file settings.php for the Drupal site, try changing the host to instead of localhost.

replace the default: 'host' => 'localhost',

with: 'host' => '',

I've had this error on OS X XAMPP, but the solution should apply here as well. As Clive mentioned, its a MySQL connection issue. This post has more on the underlying issue.

  • Neat and simple solution. It works on a per-site basis, though, but it made the trick here. Commented Nov 23, 2015 at 9:41
  • The more popular answer does not work for me (I'm using MAMP Pro), but this one does. Thanks! Commented Jun 12, 2017 at 21:53
  • 1
    No! This might get Drush to work... but it subsequently causes Drupal to fail
    – sea26.2
    Commented Jun 18, 2018 at 19:19

This was how I solved it on macOS:

sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

Source: Working with Drush on Mamp.

  • For me it was looking in "/tmp" for the mysql.sock file. So I had to create a symlink in there to my MAMP install. Just FYI for anyone that runs into that.
    – Patrick
    Commented Mar 21, 2017 at 15:36


The PDOException - error 2002 means that your drush can't connect to MySQL local database server through the socket file (e.g. /tmp/mysql.sock) as configured in your php.ini.

This is actually not much related to drush it-self, it's your PHP configuration and that error can be reproduced by:

php -r "new PDO('mysql:host=localhost;port=3306;charset=utf8;dbname=dbname', 'root', 'root');"


If your MySQL works correctly, make sure these two files:

  1. mysql_config --socket

    or: mysqladmin variables | grep socket

  2. php -i | grep -w default_socket

    or: php -r 'phpinfo();' | grep -w default_socket

matching and points to the same file and they both exists.

If not, check which one is correct by:

mysql --socket=/path/to/mysql.sock

then fix the problem by one of following solutions:

  • make the symbolic link to point to the working mysql.sock unix socket (for MAMP, see Andrew answer),

    • for example, if you're using MAMP, you can make a symbolic link to the default location:

      sudo ln -vs /Applications/MAMP/tmp/mysql /var/mysql
  • correct path of your pdo_mysql.default_socket, mysql.default_socket or mysqli.default_socket in your php.ini

  • specify unix_socket in your settings.php in your $databases variable, e.g.

    $databases['default']['default'] = array(
      // ...
      'unix_socket' => '/var/mysql/mysql.sock',


Other edge-cases could be:

  • wrong permissions (e.g. to the parent folders),
  • you're out of space,
  • you've multiple PHP versions, check which exactly are you using and which config are you changing,
  • Debug with XDebug:

    • echo '<?php xdebug_start_trace("/tmp/foo.log");' > init.php
    • drush -c init.php ev 'Database::getConnection("default", "default");'
    • or set xdebug.show_exception_trace=1 in your xdebug.ini
  • Debug: on OS X with sudo dtruss -fn mysqld, on Linux with strace
  • See also: MySQL connection not working: 2002 No such file or directory at SO

I'm using MAMP Pro and had this same issue. The easiest way I could find to fix it was to add the following line to your $database array in the settings.php file.

'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',

In full it should look like this:

$databases = array (
    'default' =>
     array (
        'default' =>
        array (
            'database' => 'your_database_name',
            'username' => 'username',
            'password' => 'password',
            'host' => 'localhost',
            'port' => '',
            'driver' => 'mysql',
            'prefix' => '',
            'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',

The exact error I was getting looked like this:

Additional uncaught exception thrown while handling exception.


PDOException: SQLSTATE[HY000] [2002] No such file or directory in drupal_is_denied() (line 2193 of ...


PDOException: SQLSTATE[HY000] [2002] No such file or directory in _registry_check_code() (line 3477 of ...

Drush command terminated abnormally due to an unrecoverable error.

  • 3
    this was the quickest and easiest fix for me using MAMP
    – aek
    Commented Feb 8, 2018 at 22:13

I solved this with the following steps, similar to previous replies but not the same.

Add a symlink:

sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

Find the php.ini being used:

php -i | grep php.ini

Add the following settings to php.ini:

pdo_mysql.default_socket= /var/mysql/mysql.sock
mysql.default_socket = /var/mysql/mysql.sock
mysqli.default_socket = /var/mysql/mysql.sock

This is due to a configuration error in your PHP/SQL configurations. Somewhere the socket that your webserver uses and the command line uses is configured differently. I recommend checking your MySQL configuration to see what unix socket is in use, and then make sure the same value is used in all php.ini configurations and compiles.

If you can't fix the configuration the following steps should work:

  1. Get the development version of Drush 5.x (http://ftp.drupal.org/files/projects/drush-All-versions-5.x-dev.tar.gz) and install that instead. This might cause other issues, but overall its pretty stable.
  2. In your Drupal sites settings.php remove the host and port settings for the database connection and add in a 'unix_socket' => '/path/to/mysql.sock' to replace them.

If all this seems to complicated, an alternative is to change the host in setting.php from localhost to This will make the site slower, but for a development site it may not be noticeable or important. For a production site you want to use the unix socket and should sort out the configuration.

  • This is really what does it. I have tested it countless times.
    – asiby
    Commented Sep 7, 2015 at 15:06

Found an easier / alternative way to install drush on a Mac:

Install homebrew by pasting this in a stand alone terminal

/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"

Then add drush by running the following from the same terminal

brew install drush

Running drush status runs fine now.


If you're working with the MySQL.com installation of MySQL, you just need to point PHP at the right location for the .sock file.

In your php.ini, add/amend these two lines:

mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock

To find the location of your php.ini (it may not exist yet), use this

php -i | grep php.ini

If the php.ini file doesn't exist there yet, create it.


I forgot that my local mysql runs on a unique port number so I was confused why I was getting this until I reviewed my configuration on another local site.

$databases['default']['default'] = array (
  'database' => 'hou',
  'username' => 'root',
  'password' => '',
  'prefix' => '',
  'host' => '',
  'port' => '3306',
  'driver' => 'mysql',
  'collation' => 'utf8mb4_general_ci',
  • I don't know why, but I changed the 'host' => 'localhost', with 'host' => '', and it is working now. Commented Nov 24, 2021 at 5:33

Agree with other answers that Drupal cannot find the mysql socket. The other answers helped me but were incomplete for installing with the official Oracle Mysql service installed. Namely, the default location of the mysql.sock file. So here is a recap of my recommended answers depending on your use case:

If using mysql as included by the official MAMP package, use @Andrew Alexander's answer:

sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

For the official Oracle MYSQL:

sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

For a MAMP 4 setup, the solution was checking "Make this version available on the command line."

MAMP configuration


I got the following message in terminal:


Blockquote Drush command terminated abnormally due to an unrecoverable error.
[error] PDOException: SQLSTATE[HY000] [2002] No such file or directory in Drupal\Component\DependencyInjection\PhpArrayContainer->createService() Blockquote

I solved the problem with the help of these instructions

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