french_dev
french_dev

Reputation: 2177

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

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.

Upvotes: 3

Views: 31681

Answers (4)

CodeToLife
CodeToLife

Reputation: 4141

In my case I had double definition of DB_HOST variable in '.env' file First one is correct:DB_HOST=127.0.0.1

And last one was DB_HOST=127.0.0.1:3306 with unwanted 3306

That was the cause.

Upvotes: 0

ᴍᴇʜᴏᴠ
ᴍᴇʜᴏᴠ

Reputation: 5256

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.

Upvotes: 0

philipjc
philipjc

Reputation: 251

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"

Upvotes: 0

Gerald Schneider
Gerald Schneider

Reputation: 17797

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.

Upvotes: 15

Related Questions