10

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?

3 Answers 3

16

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

6
  • Thanks, Andrew. This resolved a lot of issues I've been having with using env files. 👍🏼
    – Jay
    Commented Sep 21, 2018 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. Commented Nov 15, 2018 at 19:25
  • This worked for me
    – gelviis
    Commented Mar 18, 2019 at 17:31
  • 2
    This works and I like the answer better since it doesn't require configuring a socket for every environment. MAMP is causing the issue so MAMP is what you fix.
    – kmgdev
    Commented Oct 22, 2019 at 21:57
  • This was all I needed to do, thanks!
    – Recipe
    Commented Jan 3, 2021 at 14:01
14

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?

3
  • 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). Commented Jul 22, 2018 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
    Commented Aug 6, 2018 at 14:14
  • As well as turning on the setting Andrew Hahn posted below.
    – Jason Mayo
    Commented Aug 6, 2018 at 14:26
3

Jason Mayo's strategy of changing localhost to 127.0.0.1 in .env file worked for me as well 👍🏻 (MAMP Pro v6 on Mac OS 11.4 Big Sur)

1
  • This seems to be the answer that works after upgrading from MAMP 5 -> 6
    – Bryce
    Commented Nov 4, 2021 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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