MAMP PRO WP-CLI Error: Error establishing a database connection

I followed the install instructions at wp-cli.org and am unable to connect to database. I am using a newly installed (this morning) version of MAMP PRO.

which php
/usr/bin/php

echo $WP_CLI_PHP
/Applications/MAMP/bin/php/php5.5.14/bin/php

wp --info
PHP binary:     /usr/bin/php
PHP version:    5.5.14
php.ini used:   
WP-CLI root dir:    phar://wp-cli.phar
WP-CLI packages dir:    
WP-CLI global config:   
WP-CLI project config:  
WP-CLI version: 0.24.1

When I run wp <anything> in the command line, I get Error: Error establishing a database connection

3 Answers
3

I noticed a typo in the original answer, but it did work for me in my .zshrc file. The typo was the end of the last line, it was missing the final / between the php version and bin directory

#MAMP Madness
export PATH=/Applications/MAMP/Library/bin:$PATH
PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -1`
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH

Leave a Comment