2015-10-03 286 views
0

我使用PHP,Mysql和Codeignater版本3創建一個網站。然後在iPage上託管它。當我現場上傳時,我在配置文件中進行更改。mysqli :: real_connect():(HY000/2002):實時拒絕連接

$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 
); 

我使用codeignater版本3.在本地它很好。但在現場,它給出了一個錯誤。

請訪問以下鏈接http://bitshilp.com/BitShilp/index.php/home

它給出這樣的錯誤:

一個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)

文件名:核心/的common.php

行號:568

回溯:

文件:/hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitS HILP /應用/控制器/ Home.php 線:7 功能:__construct

文件:/hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/index.php 線:292 功能:require_once

謝謝。

+1

bit_root權限看起來像''bit_root'@'%''? –

+0

參數是否正確? –

+0

我希望爲了你自己的緣故,你的數據庫服務器位於'66.96.147.118'(我假設你粘貼了真實地址?出於安全原因,你不應該再這樣做)不接受該外部地址上的MySQL連接。在大多數情況下,一旦代碼在服務器上,您需要連接到本地主機或其他本地地址。 – shevron

回答

0

如果MySQL服務器啓動並運行 - 那麼這看起來像一些傳輸(如防火牆)的問題。第一步是低於嘗試telnet命令 - 如果它顯示了一個錯誤,那麼問題是不相關的PHP或MySQL:

telnet 66.96.147.118 3306 

(如果成功,將打印版本的MySQL +一些隨機字符)

0
Facing same issue in codeigniter 

$db['develop'] = array(
    'dsn' => '', 
    'hostname' => 'xxxxxxxxxxx.us-east-1.rds.amazonaws.com', 
    'username' => 'xxxxxxxx', 
    'password' => 'xxxxxxxx', 
    'database' => 'xxxxxxx', 
    'dbdriver' => 'mysqli', 
    'dbprefix' => '', 
    'pconnect' => FALSE, 
    'db_debug' => (ENVIRONMENT !== 'production'), 
    'cache_on' => FALSE, 
    'cachedir' => '', 
// 'char_set' => 'utf8', 
// 'dbcollat' => 'utf8_general_ci', 
     'char_set' => 'utf8mb4', 
     'dbcollat' => 'utf8mb4_unicode_ci', 
    'swap_pre' => '', 
    'encrypt' => FALSE, 
    'compress' => FALSE, 
    'stricton' => FALSE, 
    'failover' => array(), 
    'save_queries' => TRUE 


Not able to connect db 

A PHP Error was encountered 

Severity: Warning 

Message: mysqli::real_connect(): (HY000/2002): Connection timed out 

Filename: mysqli/mysqli_driver.php 

Line Number: 201 
0

使用AWS RDS MySQL時,出現同樣的問題。看了各種消息來源,但就此線索而言,幾乎都沒有答案。 雖然this answer幫助了我,但要考慮更新服務器上的主機名。訪問您的SSH和遵循的步驟:

cd /etc/ 
sudo nano hosts 

現在,這裏追加你的主機名:例如:

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] 

現在,配置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 
); 

哪裏35.150.12.345是您的IPv4公開IP,位於ec2-dashboard > Network Interfaces > Description : RDSNetworkInterface >> IPv4 Public IP('35 .150.12.345')。

注意:請注意,只有IPV4將在'主機名'選項中工作。主機名,cname,域將輸出數據庫連接錯誤。