I've got `PDOException: SQLSTATE[HY000] [2002] No such file or directory` when using drush
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.