Getting my head round installing plugins from the command line
So this is a MAMP/local dev issue -- run via the CLI, Craft can't connect to the db. Probably it's looking for the wrong mysql.

Check out the MAMP with Composer and MySQL on the Command Line article for details.