php SQLSTATE[HY000] [2005] 未知 MySQL 服务器主机 'mysql1.alwaysdata.com:3306' (2)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23955446/
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
SQLSTATE[HY000] [2005] Unknown MySQL server host 'mysql1.alwaysdata.com:3306' (2)
提问by french_dev
I have this errorwhen i try to access to some web pages of my project:SQLSTATE[HY000] [2005] Unknown MySQL server host 'mysql1.alwaysdata.com:3306' (2)
当我尝试访问项目的某些网页时出现此错误:SQLSTATE[HY000] [2005] Unknown MySQL server host 'mysql1.alwaysdata.com:3306' (2)
alwaysdatais the phpmyadmin websiteI use for my database.
alwaysdata是我用于数据库的phpmyadmin 网站。
I noticed that it's when I try to access in some pages in relation with the database (create user for example... etc) and there's no problems with other pages like 'contact'.
我注意到这是当我尝试访问与数据库相关的某些页面时(例如创建用户...等),并且其他页面(如“联系人”)没有问题。
I'm on mac OSX and I use MAMP server, always data, laravel and netbeans IDE. all configurations required to make the connection between my project and the database is correct.
我在 mac OSX 上,我使用 MAMP 服务器,总是数据、laravel 和 netbeans IDE。在我的项目和数据库之间建立连接所需的所有配置都是正确的。
Here it is:
这里是:
SQLSTATE[HY000] [2005] Unknown MySQL server host 'mysql1.alwaysdata.com:3306' (2)
SQLSTATE[HY000] [2005] Unknown MySQL server host 'mysql1.alwaysdata.com:3306' (2)
open: /Applications/MAMP/htdocs/lesenfantsdurhone/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php
打开:/Applications/MAMP/htdocs/lesenfantsdurhone/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php
*/
public function createConnection($dsn, array $config, array $options)
{
$username = array_get($config, 'username');
$password = array_get($config, 'password');
return new PDO($dsn, $username, $password, $options);
}
If someone have an idea...
如果有人有想法...
Thank you.
谢谢你。
回答by Gerald Schneider
The port has it's own parameter in the DSN:
'mysql:host=mysql1.alwaysdata.com;port=3306;dbname=xxx'
Alternatively just omit the port, 3306 is the default port.
或者只是省略端口,3306 是默认端口。
回答by philipjc
I had this issue while using Laravel with MAMP and Sequal Pro.
我在将 Laravel 与 MAMP 和 Sequal Pro 一起使用时遇到了这个问题。
Inside the .env
file, I set the
在.env
文件中,我设置了
DB_HOST = "localhost"
DB_PORT = "3306"
and this worked.
这有效。
Before, I had
之前,我有
DB_HOST = "localhost:8889"
回答by aexl
I kept getting this error because of the failing DNS service due to the time on my Virtualbox being off - it does that after you put your host machine to sleep for example.
由于我的 Virtualbox 时间关闭导致 DNS 服务失败,我一直收到此错误 - 例如,在您将主机置于睡眠状态之后。
Hope this helps someone in a similar situation.
希望这可以帮助处于类似情况的人。