php 出现错误 mysqli::real_connect(): (HY000/2002): 当我尝试在实时服务器上访问我的项目时没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29928109/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:40:04  来源:igfitidea点击:

Getting error mysqli::real_connect(): (HY000/2002): No such file or directory when i try to access my project on live server

phpcodeignitermysqli

提问by William

i had uploaded my website to server and then i tried to access, but the code igniter returns me that error that i don't find any answer, why is this happening?

我已将我的网站上传到服务器,然后我尝试访问,但代码点火器向我返回了我找不到任何答案的错误,为什么会发生这种情况?

my config database is set like:

我的配置数据库设置如下:

$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'netservice',
'password' => '*********',
'database' => 'valedastrutas',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE,
);

回答by Subarata Talukder

MySQL connection driver does not get any meaningful server at the location of localhost. So use,

MySQL 连接驱动程序在 localhost 的位置没有得到任何有意义的服务器。所以用,

'hostname' => '127.0.0.1' 

rather than

而不是

'hostname' => 'localhost'

回答by Asharam Seervi

Same problem occurd with me, with AWS RDS MySQL. Looked various sources, but as of this thread, almost all lack of answer. While this answerhelped me, tweak in mind to update hostnames at server. Access your SSH and follow the steps:

同样的问题发生在我身上,AWS RDS MySQL。看了各种来源,但截至本帖,几乎都没有答案。虽然这个答案对我有帮助,但请记住在服务器上更新主机名。访问您的 SSH 并按照以下步骤操作:

cd /etc/
sudo nano hosts

Now, Appending here your hostnames:For example:

现在,在此处附加您的主机名:例如:

127.0.0.1 localhost
127.0.0.1 subdomain.domain.com [if cname redirected to endpoints]
127.0.0.1 xxxxxxxx.xxxx.xxxxx.rds.amazonaws.com [Endpoints]

and now, configuring config/database.phpas follows:

现在,配置config/database.php如下:

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => '35.150.12.345',
    'username' => 'user-name-here',
    'password' => 'password-here',
    'database' => 'database-name-here',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => TRUE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

where 35.150.12.345is your IPv4 Public IP, located at ec2-dashboard > Network Interfaces > Description : RDSNetworkInterface >> IPv4 PublicIP('35.150.12.345') there.

35.150.12.345您的IPv4 Public IP在哪里,位于ec2-dashboard > Network Interfaces > Description : RDSNetworkInterface >> IPv4 PublicIP('35.150.12.345') 那里。

Note: Please note that only IPV4 will work at 'hostname' option. hostname, cname, domains will output database connection error.

注意:请注意只有 IPV4 可以在“主机名”选项下工作。hostname、cname、domains 会输出数据库连接错误。

回答by relish

I suggest you enable and look at the detailed php_errors.log

我建议你启用并查看详细的php_errors.log

Check that the directory specified using session.save_path in php.ini exists and is writable. You can use phpinfo() to show the actual session.save_path.

检查 php.ini 中使用 session.save_path 指定的目录是否存在且可写。您可以使用 phpinfo() 来显示实际的 session.save_path。

Creating the missing "phptmp" directory specified as session.save_path fixed this issue for me.

创建指定为 session.save_path 的丢失的“phptmp”目录为我解决了这个问题。

回答by Phil Smith

I had this same problem. I was using a host defined in my /etc/hosts file:

我有同样的问题。我使用的是在我的 /etc/hosts 文件中定义的主机:

127.0.0.1 test.localhost

127.0.0.1 测试.本地主机

and connecting with the url http://test.localhost/index.php/news/viewas in the tutorial. I got that error, and only fixed it by changing the line:

并与教程中的网址http://test.localhost/index.php/news/view连接。我遇到了那个错误,只能通过更改行来修复它:

'hostname' => 'localhost',

'主机名' => '本地主机',

to:

到:

'hostname' => 'test.localhost',

'主机名' => 'test.localhost',

回答by Marius

I had the same issue, in my case the site was up an running fine for a long time. Since lots of answers here concern a first time install and use I decided to tackle the same issue for systems that already function properly for a while then suddenly give this error.

我遇到了同样的问题,就我而言,该网站运行良好很长时间。由于这里的许多答案都涉及第一次安装和使用,因此我决定为已经正常运行一段时间的系统解决相同的问题,然后突然出现此错误。

First I think is important to understand the issue. As far as I know (and I may be wrong) this issue comes up if the driver cannot secure a connection to the database. This can be caused by many things, including the database being down for any issue or maintenance.

首先我认为理解这个问题很重要。据我所知(我可能是错的),如果驱动程序无法保护到数据库的连接,就会出现这个问题。这可能是由许多原因引起的,包括数据库因任何问题或维护而关闭。

In my case the issue was caused as I accessed the website during a MySQL update (Software Updater was running in the background updating MySQL components). So I had to wait for the update to complete, then the website was again up and running with no issues.

在我的情况下,问题是在 MySQL 更新期间访问网站时引起的(软件更新程序在后台运行更新 MySQL 组件)。所以我不得不等待更新完成,然后网站再次启动并正常运行。

So keep this aspect in mind, too.

所以也要记住这方面。

回答by Michal J. Figurski

I've got this error

我有这个错误

mysqli::real_connect(): (HY000/2002): No such file or directory

mysqli::real_connect(): (HY000/2002): 没有那个文件或目录

from PhpMyAdmin running on my Mac Mojave, with MySQL server also running on my Mac.

来自在我的 Mac Mojave 上运行的 PhpMyAdmin,MySQL 服务器也在我的 Mac 上运行。

Fixed it by editing PhpMyAdmin/config.inc.phpand changed the line:

通过编辑PhpMyAdmin/config.inc.php和更改行来修复它:

$cfg['Servers'][$i]['host'] = 'localhost';

to

$cfg['Servers'][$i]['host'] = '127.0.0.1';