4

I have a problem to execute this:

$ php artisan migrate

I'm getting an error

[PDOException]                             
SQLSTATE[HY000] [2002] Connection refused 

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

I have tried to set the localhost to 127.0.0.1 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??

Thanks

5
  • 1
    What happens if you use a regular php script to connect to the database? Commented Mar 27, 2014 at 23:32
  • Also check your credentials (username and password) Commented Mar 27, 2014 at 23:32
  • Try connecting via your mysql console - doesn't sound like a Laravel problem at all. Commented Mar 27, 2014 at 23:53
  • The user name and the password are ok..so I don't know what's happening. I have added the port but it doesn´t help. Commented Mar 31, 2014 at 20:09
  • As halfer mentions,doesnt look like a Laravel problem. Try to connect to mysql using console or workbench(Can you connect here?). Also, do verify the port number, mamp has different default port. Set it to 3306 for mysql. Commented Apr 1, 2014 at 8:42

4 Answers 4

6

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
Sign up to request clarification or add additional context in comments.

1 Comment

it´s not working... 'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'port' => 8889, 'database' => 'FootballApp', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', )
5

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.

2 Comments

New answers to old questions are always encouraged.
This was exactly the issue. As soon as clicked on the option and restarted the MAMP servers then the migrate worked. Thank you.
4

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,
    ],

Jeff

Comments

0

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!)

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.