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

<p>Screenshot: <a href="http://c42.co/Ur30EJ" rel="noreferrer">http://c42.co/Ur30EJ</a><a href="https://i.sstatic.net/XMGlN.png" rel="noreferrer"><img src="https://i.sstatic.net/XMGlN.png" alt="enter image description here"></a></p>

CC BY-SA 4.0
2018-09-21T10:43:58.197Z
Thanks, Andrew. This resolved a lot of issues I've been having with using env files. 
Jay
CC BY-SA 4.0
2018-11-15T19:25:03.927Z
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.
Duncan Micahel-MacGregor
CC BY-SA 4.0
2019-03-18T17:31:53.350Z
This worked for me
gelviis
CC BY-SA 4.0
2019-10-22T21:57:44.403Z
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
CC BY-SA 4.0
2021-01-03T14:01:41.457Z
This was all I needed to do, thanks!
Recipe
CC BY-SA 4.0
2021-03-03T10:16:17.530Z
same here, installation of craftcms goes thru now
nerdess
CC BY-SA 4.0
2018-06-03T02:53:15.287Z
2018-06-03T02:53:15.287Z
Andrew Hahn
<p>Jason Mayo's strategy of changing <code>localhost</code> to <code>127.0.0.1</code> in .env file worked for me as well  (MAMP Pro v6 on Mac OS 11.4 Big Sur)</p>

CC BY-SA 4.0
2021-11-04T21:13:44.783Z
This seems to be the answer that works after upgrading from MAMP 5 -> 6
Bryce
CC BY-SA 4.0
2021-06-03T20:12:43.123Z
2021-06-03T20:12:43.123Z
Roger Glenn
<p>After playing with this a little further it seems the unixSocket setting is necessary to get this working so I added:</p>

<pre><code>'unixSocket' =&gt; getenv('DB_SOCKET')
</code></pre>

<p>To <code>config/db.php</code> and then added:</p>

<pre><code>DB_SOCKET="/Applications/MAMP/tmp/mysql/mysql.sock"
</code></pre>

<p>To my <code>.env</code> 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?</p>

CC BY-SA 4.0
2018-07-22T00:07:24.527Z
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
CC BY-SA 4.0
2018-08-06T14:14:30.493Z
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
CC BY-SA 4.0
2018-08-06T14:26:36.353Z
As well as turning on the setting Andrew Hahn posted below.
Jason Mayo
CC BY-SA 3.0
2017-12-05T21:07:08.090Z
2017-12-05T21:07:08.090Z
Tim Knight
<p>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 <a href="https://mijingo.com/lessons/craft-3-command-line/" rel="noreferrer">https://mijingo.com/lessons/craft-3-command-line/</a> I realized that wasn't the case (and with RC1 being released today).</p>

<p>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.</p>

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

<pre><code>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
</code></pre>

<p>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?</p>

<craft3><installation><mysql><cli>
Craft CLI RC1 Connectivity Issues with MAMP Pro
# Craft CLI RC1 Connectivity Issues with MAMP Pro

(Asked by: username_0 on 2017-12-05)

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?

**Tags:** craft3, installation, mysql, cli


---

## 3 answers

### Answer by username_0 on 2017-12-05. Score: 14 | Accepted answer

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?

> **Comments:**
> **username_10**: 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).  
> **username_11**: 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  
> **username_11**: As well as turning on the setting username_1 posted below.  

---

### Answer by username_1 on 2018-06-03. Score: 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/Ur30EJ>[![enter image description here](https://i.sstatic.net/XMGlN.png)](https://i.sstatic.net/XMGlN.png)

> **Comments:**
> **username_2**: Thanks, Andrew. This resolved a lot of issues I've been having with using env files.   
> **username_3**: 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.  
> **username_4**: This worked for me  
> **username_5**: 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.  
> **username_6**: This was all I needed to do, thanks!  
> **username_7**: same here, installation of craftcms goes thru now  

---

### Answer by username_8 on 2021-06-03. Score: 3

username_11'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)

> **Comments:**
> **username_9**: This seems to be the answer that works after upgrading from MAMP 5 -> 6  

---

