MySQL 拉拉维尔;“SQLSTATE[HY000] [2002] 连接被拒绝”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28385251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel; "SQLSTATE[HY000] [2002] Connection refused"
提问by Hanimar
I set up homestead 2.0 on OSX host and using Sequel Pro.
我在 OSX 主机上设置了 homestead 2.0 并使用 Sequel Pro。
I can do migration and confirm that data are migrated in Sequel Pro, so it looks like no problem about DB connection.
我可以做迁移并确认数据在Sequel Pro中迁移,所以看起来数据库连接没有问题。
But once I try to fetch data from Laravel 4.2 app, it fails to retrieve data and get following error.
但是一旦我尝试从 Laravel 4.2 应用程序获取数据,它就无法检索数据并出现以下错误。
PDOException (2002)
SQLSTATE[HY000] [2002] Connection refused
Here is my mysql configuration.
这是我的mysql配置。
'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,
Sequel pro设置同上,
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.
我尝试将主机名更改为 'localhost',homestead destroy 和 up,但没有工作。为什么??任何建议都有帮助。
回答by daneczech
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!
为我工作。总是比我们期望的更简单!
回答by Lekz Flores
For other devs there who are running Laravel on it's latest version (5.3) I just change these lines:
对于在最新版本 (5.3) 上运行 Laravel 的其他开发人员,我只需更改以下几行:
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.
显然,33060
将转换为3306
但现在无法解释为什么localhost
要工作。
回答by Jesús Mu?oz
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.
我解决了将 Laravel 的 .env 文件中主机参数上的地址 127.0.1.1 替换为 localhost 的问题。我正在使用 GNU/Linux Debian 8、Laravel 5.6.3、PHP 7.1.8、Apache 2.4.27 和 (Mysql) 10.1.26-MariaDB。
回答by Studione
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.
我通过更新 mariadb 解决了这个问题。我检查了“brew outdated”过时的内容,然后使用“brew upgrade mariadb”重新加载 vagrant 更新了 mariadb,问题已解决。希望这对你有用。
回答by FabricioG
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.
由于某种原因,我遇到了同样的问题,以上都没有奏效。对我来说,我在 .env 中尝试了这个,我将 DB_HOST 更改为 homestead.local。霍姆斯特德是我网站的名称。这奏效了。
DB_HOST=homestead.local
回答by Sameer Shaikh
'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
试试这个它可能对你有用