SQLSTATE[HY000] [2005] Unknown MySQL server host 'mysql1.alwaysdata.com:3306' (2)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 13:38:22

问题


I have this error when i try to access to some web pages of my project:SQLSTATE[HY000] [2005] Unknown MySQL server host 'mysql1.alwaysdata.com:3306' (2)

alwaysdata is the phpmyadmin website I use for my database.

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.

Here it is:

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

 */
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.


回答1:


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.




回答2:


I had this issue while using Laravel with MAMP and Sequal Pro.

Inside the .env file, I set the

DB_HOST = "localhost"
DB_PORT = "3306"

and this worked.

Before, I had

DB_HOST = "localhost:8889"



回答3:


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.

Hope this helps someone in a similar situation.



来源:https://stackoverflow.com/questions/23955446/sqlstatehy000-2005-unknown-mysql-server-host-mysql1-alwaysdata-com3306-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!