首页 > 解决方案 > 消息:mysqli::real_connect(): (HY000/2002)

问题描述

嗨,当我尝试连接 MySql 数据库时,在我的 codeigniter 应用程序中发生了以下错误。

消息:mysqli::real_connect(): (HY000/2002):连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应。

我使用的是 Windows 10 系统

XAMPP v3.2.2

PHP 版本 7.2.4

phpmyadmin 4.8.1

Codeigniter 配置设置

    'dsn'      => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'XXXXXX',
    'dbdriver' => 'mysqli',
    'dbprefix' => 'ss_',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'development'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt'  => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE

有些人建议将主机名更改为 127.0.0.1,但这对我不起作用,其中一些人建议编辑System32\drivers\etc\host设置但我没有得到任何肯定的结果,这里我也附上主机设置

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost

标签: phpmysqlcodeignitermysqli

解决方案


推荐阅读