I've been trying to run the new Craft CLI for the last couple of versions without any success. I figured maybe since we weren't at RC1 yet that it wasn't fully working. After seeing Ryan's video about it at https://mijingo.com/lessons/craft-3-command-line/ I realized that wasn't the case (and with RC1 being released today).

I am using MAMP Pro (like Ryan does in his video), but I have it using the standard MySQL port at 3306. I also have PHP 7.1 installed at the terminal through homebrew and pdo_mysql is a compiled in module. I am also using RC1.

Interestingly, if I use localhost I get a completely different message than if I use 127.0.0.1. But regardless, both still fail.

Which database driver are you using? [mysql,pgsql,?]: mysql
Database server name or IP address: [localhost] localhost
Database port: [3306] 3306
Database username: [root] root
Database password:
Database name: craft3
Database table prefix:
Testing database credentials... failed: SQLSTATE[HY000] [2002] No such file or directory

Which database driver are you using? [mysql,pgsql,?]: mysql
Database server name or IP address: [localhost] 127.0.0.1
Database port: [3306] 3306
Database username: [root] root
Database password:
Database name: [craft3] craft3
Database table prefix:
Testing database credentials... failed: SQLSTATE[HY000] [2002] Connection refused

If I create the database manually and put the credentials into my .env file everything connects just fine without any issue. Is there something else I should be considering?

up vote 11 down vote accepted

After playing with this a little further it seems the unixSocket setting is necessary to get this working so I added:

'unixSocket' => getenv('DB_SOCKET')

To config/db.php and then added:

DB_SOCKET="/Applications/MAMP/tmp/mysql/mysql.sock"

To my .env file. After that, the installation will go through using the CLI. Perhaps there's still an option that doesn't require the unixSocket be set?

  • I've been running into this problem using MAMP Pro and MySQL and this answer worked for me. When I use a separately set up Postgres database the additions are not needed (perhaps obviously). – Jack McKenzie Jul 22 at 0:07
  • This solution didn't fix the problem for me as the file in /Applications/MAMP/tmp/mysql/mysql.sock just did not exist! But, a simple solution was instead of using localhost when running craft setup in terminal, I used 127.0.0.1 and it all ran smoothly – Jason Mayo Aug 6 at 14:14
  • As well as turning on the setting Andrew Hahn posted below. – Jason Mayo Aug 6 at 14:26

I gave everything a try, but the only thing that worked for me was ensuring "Allow network access to MySQL" was ticked in MAMP.

Screenshot: http://c42.co/Ur30EJenter image description here

  • Thanks, Andrew. This resolved a lot of issues I've been having with using env files. 👍🏼 – Jay Sep 21 at 10:43

Thanks Andrew! that setting tip helped me fix it.

Also worth noting! I couldn't get past the setup with a blank password, I had to use "root" as the password to get it to work.

New contributor
Duncan Micahel-MacGregor is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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