php mysqli::real_connect(): (HY000/2002): 实时连接被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32919571/
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
mysqli::real_connect(): (HY000/2002): Connection refused on Live
提问by sandip chandak
I create a web site using PHP, Mysql, and Codeignater version 3. Then host it on iPage. When I upload on live I make changes in config file.
我使用 PHP、Mysql 和 Codeignater 版本 3 创建了一个网站。然后将它托管在 iPage 上。当我实时上传时,我会在配置文件中进行更改。
$db['default'] = array(
'dsn' => '',
'hostname' => '66.96.147.118',
'username' => 'bit_root',
'password' => 'root',
'database' => 'bit_shilp',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
I use codeignater version 3. On local it work great. But on live site It gives an error.
我使用 codeignater 版本 3。在本地它工作得很好。但是在实时站点上它给出了错误。
Please see this link http://bitshilp.com/BitShilp/index.php/home
请参阅此链接http://bitshilp.com/BitShilp/index.php/home
It gives an error like this:
它给出了这样的错误:
A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): (HY000/2002): Connection refused
Filename: mysqli/mysqli_driver.php
Line Number: 161
Backtrace:
File: /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/application/controllers/Home.php Line: 7 Function: __construct
File: /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/index.php Line: 292 Function: require_once A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/system/core/Exceptions.php:272)
Filename: core/Common.php
Line Number: 568
Backtrace:
File: /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/application/controllers/Home.php Line: 7 Function: __construct
File: /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/index.php Line: 292 Function: require_once
遇到 PHP 错误
严重性:警告
消息:mysqli::real_connect():(HY000/2002):连接被拒绝
文件名:mysqli/mysqli_driver.php
行号:161
回溯:
文件:/hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/application/controllers/Home.php 行:7 功能:__construct
文件:/hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/index.php 行:292 功能:require_once 遇到 PHP 错误
严重性:警告
消息:无法修改标头信息 - 标头已发送(输出开始于 /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/system/core/Exceptions.php:272)
文件名:core/Common.php
行号:568
回溯:
文件:/hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/application/controllers/Home.php 行:7 功能:__construct
文件:/hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/index.php 行:292 功能:require_once
Thanks.
谢谢。
回答by noonex
If MySQL Server is up and running - then this looks like some transport (e.g. firewall) problem. First step is to try telnet command below - if it shows an error, then problem is not related to PHP or MySQL :
如果 MySQL 服务器已启动并正在运行 - 那么这看起来像是一些传输(例如防火墙)问题。第一步是尝试下面的 telnet 命令 - 如果显示错误,则问题与 PHP 或 MySQL 无关:
telnet 66.96.147.118 3306
(On success it will print mysql version + some random characters)
(成功后会打印 mysql 版本 + 一些随机字符)
回答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.php
as 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.345
is your IPv4 Public IP, located at ec2-dashboard > Network Interfaces > Description : RDSNetworkInterface >> IPv4 Public
IP('35.150.12.345') there.
35.150.12.345
您的IPv4 Public IP在哪里,位于ec2-dashboard > Network Interfaces > Description : RDSNetworkInterface >> IPv4 Public
IP('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 会输出数据库连接错误。