2

First off let me say that I solved my problem of sqlstate[hy000] [2002] connection refused by following this stackoverflow question: Laravel: SQLSTATE[HY000] [2002] Connection refused

However I'm confused as to why localhost works and 127.0.0.1 doesn't. Can someone explain the differences? I thought they were the same thing so long as your 127.0.0.1 was mapped to localhost in your /etc/hosts file.

Not really too sure if this questions needs more information then that, if you do, i'll be glad to provide it.

Edit: Sorry if this is a poorly worded question, I put the question as simply as possible. Considering that the 'problem' of this question no longer exists, I'm really just looking for more of an explanation as to why the answer in the above Stackoverflow Question worked. Not much information was given in that answer. Poorly given answer if I do say so myself.

Edit 2: My system setup consists of Virtualbox, Vargant, and Laravel Homestead. I have a vagrant box set up with the mysql port at 33060 (Standard port upon setup). I'm able to connect via SQLPro to 127.0.0.1:33060 just fine. However through my Laravel app I'm not able to connect via 127.0.0.1 only localhost. Is this still an issue with my configuration of mysql if i'm able to connect using both localhost in the app, and 127.0.0.1 in SQLPro? Doesn't this mean that I should be able to connect to either or and vise versa?

J. Robinson
  • 931
  • 4
  • 17
  • 45
  • See https://serverfault.com/questions/295285/mysql-cannot-connect-via-localhost-only-127-0-0-1?rq=1 – Shadow Jul 19 '17 at 03:08

1 Answers1

1

As explained in this serverfault question MySQL cannot connect via “localhost”, only 127.0.0.1, mysql connects to a unix socket when localhost is specified, but connects to a network socket if 127.0.0.1 is provided.

Depending on how your mysql is configured, not both channels may be available. Also, operating system or firewall configurations may also prevent mysql from using the network connection.

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • You have to check how sqlpro connects to mysql via tracing the connection. I do not know that application. – Shadow Jul 19 '17 at 03:28
  • Ok, so because its two different applications.... i thought they connected the same way... i thought all applications did. lol just different commands to run the connection... PDO for php, etc. – J. Robinson Jul 19 '17 at 03:50