Home » Php » php artisan migrate error PDOException in Laravel 4

php artisan migrate error PDOException in Laravel 4

Posted by: admin November 29, 2017 Leave a comment


I have a problem to execute this:

$ php artisan migrate

I’m getting an error

SQLSTATE[HY000] [2002] Connection refused 

I’m using MAMP and it’s working ok.

I have tried to set the localhost to and I’ve added 'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock' but nothing helps.

[Edit] also I’ve added the port and I have checked the user and the password are correct and the server is running properly.. any suggestion??



Not sure but make sure your mysql server is running and it’s running on the right port as expected because, Laravel‘s default port value is 3306 (it’s the default port of mysql server) and most probably mysql is running on a different port. Here is a discussion and also check this answer, it’s almost similar.

Also follow this thread which discussed and solved the same error you mentioned in your question:

[SOLVED] SQLSTATE[HY000] [2002] Connection refused


change .env file in laravel :
add MAMP mysql port

'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'forge'),
        'username'  => env('DB_USERNAME', 'forge'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'port'      => '8889',
        'strict'    => false,



I know this is an old question, but it came up as the first result in Google when I had the same problem, so I wanted to add my solution here in case it helps someone else.

In MAMP when you click on MySQL, there is a setting to “Allow network access to MySQL” that needs to be enabled for Laravel to access the database (it wasn’t enabled by default for me). This allows your application to connect to MySQL without using a Unix socket.


Yes, had exactly this problem, with MAMP need to add to config/database ‘port’ => ‘8889’ (assuming yu are using this port, rather than 80 which can cause conflicts with others apps like Skype!)