8

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.

Hanimar
  • 91
  • 1
  • 1
  • 4
  • MySQL's port is usually `3306`, not `33060`. You may have set up your system somewhat differently, though. Double check it. – O. Jones Feb 07 '15 at 18:18
  • `33060` is correct for Sequel because that's the port the homestead VM forwards to your host machine. For you App you need `3306` because it runs inside the homestead VM. – cgross Feb 07 '15 at 20:20
  • Changed Sequel to '33060' and homestead port '3306', but no work. – Hanimar Feb 08 '15 at 01:32
  • Does this answer your question? [SQLSTATE\[HY000\] \[2002\] Connection refused within Laravel homestead](https://stackoverflow.com/questions/35394230/sqlstatehy000-2002-connection-refused-within-laravel-homestead) – shmuels Aug 24 '20 at 20:24

7 Answers7

16

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!

daneczech
  • 655
  • 1
  • 9
  • 20
3

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.

Lekz Flores
  • 468
  • 10
  • 27
1

I solved the problem substituting the address 127.0.1.1 to localhost on the host parameter in the Laravel's .env file. I am working over GNU/Linux Debian 8, Laravel 5.6.3, PHP 7.1.8, Apache 2.4.27 and (Mysql) 10.1.26-MariaDB.

0
'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'homestead',
            'username'  => 'homestead',
            'password'  => 'secret',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => ''

Try this out it might work for you

Sameer Shaikh
  • 7,564
  • 2
  • 17
  • 32
0

I encountered the same problem for some reason neither of the above worked. For me I tried this in .env I changed DB_HOST to homestead.local. Homstead being the name of my site. This worked.

DB_HOST=homestead.local
FabricioG
  • 3,107
  • 6
  • 35
  • 74
0

I solved the problem by updating mariadb. I've checked what was outdated with 'brew outdated', then updated mariadb with 'brew upgrade mariadb' reload vagrant and issue was fixed. Hope this works for you.

0

Check your .env file for MYSQL_SSL=true. We use SSL for MySQL in production not on dev after commenting the #MYSQL_SSL=true migration ran successfully.

AyoAyomide
  • 71
  • 1
  • 4