If you can't connect to your database there are a few possibilities. One of them is, that you're using MAMP, like in your and my case, but WP-CLI is not using the MAMP PHP binary. You can check that by running
wp --info
To specify the MAMP PHP binary you'll need to modify your PATH
enviroment variable. You have to add
PHP_VERSION=$(ls /Applications/MAMP/bin/php/ | sort -n | tail -1)
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH
to your ~/.bash_profile
or ~/.zsh_profile
If you want to use a specific PHP Version (eg. 5.5.26) just use
export PATH=/Applications/MAMP/bin/php/php5.5.26/bin:$PATH
After saving the file run:
source ~/.bash_profile
and
wp --info
to check your changes.
For further reading check the WP-CLI Handbook for using a custom PHP binary