首页 文章

mysqli :: real_connect():( HY000 / 2002):Live上连接被拒绝

提问于
浏览
0

我使用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
);

我使用codeignater版本3.在本地它工作得很好 . 但在现场网站上它会出错 .

请看这个链接http://bitshilp.com/BitShilp/index.php/home

它给出了这样的错误:

遇到PHP错误严重性:警告消息:mysqli :: real_connect():( HY000 / 2002):连接被拒绝文件名:mysqli / mysqli_driver.php行号:161 Backtrace:文件:/ 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 Backtrace:文件:/hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/application/controllers/Home.php行:7功能:__构造文件:/hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/index.php行:292功能:require_once

谢谢 .

3 回答

  • 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
    

    Now, Appending here your hostnames: 例如:

    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')那里 .

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

相关问题