SQLSTATE [HY000] [2005]未知的MySQL服务器主机'localhost:3306'(2) [英] SQLSTATE[HY000] [2005] Unknown MySQL server host 'localhost:3306' (2)

查看:273
本文介绍了SQLSTATE [HY000] [2005]未知的MySQL服务器主机'localhost:3306'(2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我在laravel中面临上述问题.基本上,这个项目是在Mac OS x上安装的,目前我正在Linux上进行开发.所以当我在浏览器上运行它时,它给了我这个错误.我还更改了数据库文件中的数据库详细信息.但是现在这个错误来了.所以你能告诉我我该怎么解决.

currently i am facing above problem in laravel. basically this project is setup on mac OS x and currently i am working on it in Linux. so when i run it is on browser it give me that error. i have also changed the my database details in database file. but now this error comes. so can you please tell me how can i fix it.

打开:/var/www/laravel-projects/wit/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php

Open: /var/www/laravel-projects/wit/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);
}

谢谢

推荐答案

我相信在5.5之前的php版本中,您将使用"localhost"(或mysql服务器在不同主机上运行的主机) 主机"参数.如果是5.5版本之后,我认为您需要使用"localhost:3306"(不一定是3306,这只是默认的mysql端口,因此如果您进行更改,它将有所不同).因此,如果您使用的是5.5之前的php版本,并且该代码适用于5.5及更高版本,请尝试更改mysql连接器设置.猜它看起来像:

I believe in versions of php prior to 5.5 you would use "localhost" (or the host the mysql server is running on if it's not the same host) for the 'host' parameter. If it is after version 5.5 I think you need to use "localhost:3306" (Not necessarily 3306, this is just the default mysql port, so if you changed that it will be different) . So if you are on a version of php prior to 5.5 and the code is for verion 5.5 and greater, try changing your mysql connector settings. Guessing it looks something like:

array(
        'host' => "localhost:3306",
        'username' => 'user',
        'password' => 'pass',
        'dbname' => 'database');
)

也许尝试将其更改为:

array(
            'host' => "localhost",
            'username' => 'user',
            'password' => 'pass',
            'dbname' => 'database');
    ) 

这篇关于SQLSTATE [HY000] [2005]未知的MySQL服务器主机'localhost:3306'(2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆