Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel; "SQLSTATE[HY000] [2002] Connection refused"

I set up homestead 2.0 on OSX host and using Sequel Pro.

I can do migration and confirm that data are migrated in Sequel Pro, so it looks like no problem about DB connection.

But once I try to fetch data from Laravel 4.2 app, it fails to retrieve data and get following error.

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

Here is my mysql configuration.

'mysql' => array(
            'driver'    => 'mysql',
            'host'      => '127.0.0.1',
            'port'      => '33060',
            'database'  => 'homestead',
            'username'  => 'homestead',
            'password'  => 'secret',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => ''

Sequel pro setting is same above,

Name: 127.0.0.1    
Host: 127.0.0.1
Username: homestead
Password: secret
Database:     
Port: 33060

I tried change host name to 'localhost', homestead destroy and up, but No work. Why?? Any suggestion helps.

like image 328
Hanimar Avatar asked Feb 07 '15 17:02

Hanimar


Video Answer


2 Answers

I had exactly the same issue and I'm not sure why this happens. However changing

'host'      => '127.0.0.1',

to

'host'      => 'localhost',

worked for me. Always simpler than what we expect!

like image 197
daneczech Avatar answered Sep 20 '22 06:09

daneczech


For other devs there who are running Laravel on it's latest version (5.3) I just change these lines:

DB_HOST=127.0.0.1
DB_PORT=3306

Into this:

DB_HOST=localhost
DB_PORT=33060

Obviously, 33060 will be converted into 3306 but can't explain by now why localhost should work.

like image 36
Lekz Flores Avatar answered Sep 23 '22 06:09

Lekz Flores