Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nhayder's avatar
Level 13

Can't Connect to BD after upgrading MAMP server from 4 to 5

i'm using MAMP 4.* on a macbook pro while building laravel 5.8 app, i have updated MAMP servier from 4 to 5 since then my laravel app couldn't connect to sql DB Correctly.

This is my .env file

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=mydb
DB_USERNAME=root
DB_PASSWORD=root

i'm getting this error

SQLSTATE[HY000] [2002] Connection refused

Ironically ??? i can connect o to my DB using the same settings from terminal like this

/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot

After clearing the cache

php artisan config:clear

i'm still getting same error????

i'm struggling through this for a couple of days now i have noticed that my terminal prompt is showing different name that what i usually see

prompt

hassanmansoor@hassan-MBP ~ %  // and the terminal window title is zsh which is totally new to me????

i'm not sure what is MBP ??? never seen this before ????

Don't anyone been in similar situation ???

Is there is any fix for this issue ????

0 likes
15 replies
nhayder's avatar
Level 13

That would be a good option but I was trying to fix current problem as my priority

BryanK's avatar

You might want to verify your setup.

See what's running and its location:

ps -ef | grep mysqld

See what port it's on:

sudo lsof -Pnl +M -i | grep mysqld

1 like
nhayder's avatar
Level 13

@bryank thank you for your help, this command ps -ef | grep mysqld returned

501  8076     1   0  5:54PM ??         0:00.02 /bin/sh /Applications/MAMP/Library/bin/mysqld_safe --port=8889 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log
  501  8188  8076   0  5:54PM ??         0:01.51 /Applications/MAMP/Library/bin/mysqld --basedir=/Applications/MAMP/Library --datadir=/Applications/MAMP/db/mysql57 --plugin-dir=/Applications/MAMP/Library/lib/plugin --log-error=/Applications/MAMP/logs/mysql_error_log.err --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --socket=/Applications/MAMP/tmp/mysql/mysql.sock --port=8889
  501  9709  9703   0 10:16PM ttys002    0:00.00 grep mysqld

and this sudo lsof -Pnl +M -i | grep mysqld returned

mysqld    8188      501   32u  IPv6 0xa441e6cdfc52abd1      0t0  TCP *:8889 (LISTEN)

dos these help ????

jlrdw's avatar

Did you look at the S.O. post, it talks about ports changed.

nhayder's avatar
Level 13

I tried to change the port but still not getting connected

jlrdw's avatar

I had trouble once with a wamp setup, I ended up having to uninstall then reinstall. I've been pretty lucky ever since.

1 like
BryanK's avatar

@nhayder

Change your port in the .env to 8889. For whatever reason, your config is not on the default port.

DB_PORT=8889
1 like
nhayder's avatar
Level 13

Yah tried that and still not connecting

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=8889
DB_DATABASE=mydb
DB_USERNAME=root
DB_PASSWORD=root
nhayder's avatar
Level 13

ok i found the fix for the problem but to tell you the truth its not a good way to solve this issue so im wondering if anybody can help me out in getting better solution for this issue.

according to this post https://stackoverflow.com/questions/46407490/laravel-no-such-file-or-directory-sql-create-table-migrations

i was able to fix the issue by adding this line of code to App/config/database.php

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            // 'unix_socket' => env('DB_SOCKET', ''),
            'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'), <----- this is the line
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

then i was able to connect to DB normally using these settings

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mydb
DB_USERNAME=root
DB_PASSWORD=root

can somebody explain how does that fix the problem and if there is a better fix

any ideas

1 like
nhayder's avatar
Level 13

@jlrdw Yah nailed it this time thanks to you, I just changed the port on MAMP from 8889 to 3306 and this came back to normal.

Thanks man

Please or to participate in this conversation.