php - 消息: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
解决方案
推荐阅读
- javascript - 创建一个列表,其中有用户单击并悬停一个元素的按钮,以打开另一个
- .net-core - .net 核心 web api jwt
- unit-testing - grails 3中的自定义验证器名称
- service - 有没有办法将 EKS 服务配置为使用 HTTPS?
- rest - 如何在不使用动词的情况下创建用于下载文件的 URI?
- azure - 如何将文本翻译服务添加到我的 Azure 帐户
- jquery - 我怎样才能使这些漂亮的复选框像其他按钮一样通过 AJAX 发布?
- sql - Postgres - 使用 where 子句 + distinct 左连接
- python - 如何优化 Python 中的 if 语句:首先是更可能的情况还是更昂贵的情况?
- python - 在 Windows 上使用 OpenCV 和 Python 进行硬件加速解码(MSMT / IntelMFX / FFMPEG / 任何后端)