首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計綜合問答

XAMPP phpMyAdmin #2002 錯誤:端口修改後配置文件同步解決

     編輯:程式設計綜合問答

問題現象

XAMPP 修改 MySQL 端口 3306 → 3307 (避開 Lantern 衝突) 後,phpMyAdmin 報錯:

#2002 - The server is not responding

錯誤截圖

已嘗試修改 config.inc.php 和 my.ini 中的 host 為 127.0.0.1,無效。

根本原因

phpMyAdmin 配置文件 config.default.php 中端口配置留空,默認讀取 3306,與實際 3307 不符。

解決步驟

  1. 定位文件:xampp\phpMyAdmin\libraries\config.default.php
  2. 搜索:$cfg['Servers'][$i]['port']
  3. 修改:
    // 原
    $cfg['Servers'][$i]['port'] = '';
    // 改
    $cfg['Servers'][$i]['port'] = '3307';
    
  4. 重啟 Apache (XAMPP 控制面板)
  5. 訪問 phpMyAdmin 正常

關鍵配置文件對比

文件作用需修改項
my.iniMySQL 服務端配置port=3307
php.iniPHP MySQL 擴展默認連接mysqli.default_port=3307
config.inc.phpphpMyAdmin 用戶配置 (優先)$cfg['Servers'][$i]['port'] = '3307';
config.default.phpphpMyAdmin 默認配置 (備用)$cfg['Servers'][$i]['port'] = '3307';

原理說明

  • phpMyAdmin 讀取配置優先級:config.inc.php > config.default.php
  • port = '' 時,PHP MySQL 驅動默認連接 3306
  • 端口被占用/不匹配 → 連接失敗 → #2002

避坑指南

  1. 修改 MySQL 端口後,**必須同步更新所有客戶端配置**
  2. 優先編輯 config.inc.php (用戶配置),避免升級覆蓋
  3. 使用 netstat -ano | findstr "3307" 確認端口監聽正常
  4. 防火牆放行 3307 端口

總結

XAMPP 修改 MySQL 端口後 phpMyAdmin #2002 錯誤,核心在於 config.default.php 端口配置留空導致默認回退 3306。顯式設置 $cfg['Servers'][$i]['port'] = '3307' 即可解決。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved