You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

XAMPP中无法打开phpMyAdmin,提示访问被拒及连接错误求助

Fixing "mysqli_real_connect(): (HY000/2002)" Error in XAMPP phpMyAdmin

First, let's look at the exact error you're facing:

mysqli_real_connect(): (HY000/2002): A socket operation was attempted to an unreachable host.
Connection for controluser as defined in your configuration failed.
mysqli_real_connect(): (HY000/2002): A socket operation was attempted to an unreachable host.
phpMyAdmin尝试连接MySQL服务器,但服务器拒绝了连接。您应检查配置中的主机、用户名和密码,确保与MySQL服务器管理员提供的信息一致。

This issue typically stems from MySQL not running, misconfigured phpMyAdmin settings, or connection blocks. Let's work through fixes step by step:

  • Confirm MySQL Service is Active
    Open your XAMPP Control Panel and check the MySQL module. If it's not labeled Started, click the Start button. If it fails to launch, port 3306 (MySQL's default) is likely occupied by another app. To fix this:

    1. Open XAMPP/mysql/bin/my.ini (or my.cnf on some systems)
    2. Find the line port=3306 and change it to port=3307 (or any unused port)
    3. Save the file and restart the MySQL service in XAMPP
  • Validate phpMyAdmin Configuration
    Navigate to XAMPP/phpMyAdmin/config.inc.php and check these critical settings:

    • Set $cfg['Servers'][$i]['host'] to '127.0.0.1' (using the IP instead of localhost avoids socket-related glitches in some cases)
    • Double-check the control user credentials: $cfg['Servers'][$i]['controluser'] and $cfg['Servers'][$i]['controlpass']. By default, XAMPP uses pma as the control user with an empty password. If you've modified MySQL users, ensure this user exists with proper permissions. If unsure, you can temporarily comment out these two lines to skip the control user check.
    • Make sure $cfg['Servers'][$i]['password'] matches your MySQL root password (if you set one)
  • Check for Firewall/Antivirus Interference
    Your local firewall or antivirus might be blocking the connection between phpMyAdmin and MySQL. Try temporarily disabling them to test. If the issue goes away, add an exception for MySQL (port 3306 or your custom port) in your security software.

  • Reset MySQL Root Password (if necessary)
    If you suspect an incorrect password, reset it via XAMPP's shell:

    1. Open XAMPP Control Panel, click Shell next to MySQL
    2. Run the command: mysqladmin -u root password "your-new-password"
    3. Update $cfg['Servers'][$i]['password'] in config.inc.php to match the new password

内容的提问来源于stack exchange,提问作者Shaan Alam

火山引擎 最新活动