You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求协助排查phpMyAdmin连接MySQL服务器失败问题

Hey there, let's work through this phpMyAdmin connection error together. The "server refused connection" message usually boils down to a handful of common issues—let's break them down step by step to get you connected:

1. Double-check your phpMyAdmin configuration settings

First, track down your config.inc.php file (it’s usually in your phpMyAdmin installation folder—think /usr/share/phpmyadmin/ on Linux, or C:\xampp\phpMyAdmin\ if you’re using XAMPP). Open it up and verify these critical lines:

  • $cfg['Servers'][$i]['host']: Make sure this matches your MySQL server’s host. For local setups, it’s typically localhost or 127.0.0.1—sometimes localhost uses a Unix socket while 127.0.0.1 uses TCP/IP, so try switching if one fails. For remote servers, use the actual IP or hostname provided by your admin.
  • $cfg['Servers'][$i]['user']: Confirm this is the correct MySQL username (like root for local installs, or the dedicated user your admin gave you).
  • $cfg['Servers'][$i]['password']: Double-check the password matches exactly—typos here are super common! If you’re using a blank password (not recommended, but possible), ensure this line is set to '' (empty quotes).
2. Confirm MySQL is actually running

If your config looks spot-on, the next step is to check if MySQL is up and running:

  • On Linux: Run sudo systemctl status mysql (or mariadb if you’re using MariaDB). If it’s stopped, fire it up with sudo systemctl start mysql.
  • On Windows (XAMPP/WAMP): Open your control panel and make sure the MySQL service is marked as "Running". If not, click "Start" to launch it.
  • On macOS: If you installed MySQL via Homebrew, run brew services list to check status, then brew services start mysql if it’s inactive.
3. Verify MySQL user privileges

Even if your username and password are correct, the user might not have permission to connect from your phpMyAdmin’s host:

  • Log into MySQL directly via the command line: run mysql -u your_username -p and enter your password when prompted.
  • Run this query to check the user’s allowed hosts:
    SELECT user, host FROM mysql.user WHERE user = 'your_username';
    
  • If the host listed is something specific (like 192.168.1.100) but phpMyAdmin is connecting from localhost, you’ll need to update the privileges. Run these commands:
    GRANT ALL PRIVILEGES ON *.* TO 'your_username'@'localhost' IDENTIFIED BY 'your_password';
    FLUSH PRIVILEGES;
    
    (Replace your_username, localhost, and your_password with your actual details. Use % instead of localhost if you want the user to connect from any host, but note that’s less secure.)
4. Check for firewall or port blocking

MySQL uses port 3306 by default—make sure your firewall isn’t blocking this port:

  • On Linux (UFW): Run sudo ufw status to check if port 3306 is allowed. If not, add a rule with sudo ufw allow 3306.
  • On Windows: Open Windows Defender Firewall > Advanced Settings > Inbound Rules, and confirm there’s a rule allowing traffic on port 3306 for MySQL.
  • For remote servers: Ensure the server’s firewall allows incoming connections on port 3306 from your IP address.
5. Fix Unix socket mismatches (local connections only)

If you’re using localhost as the host in phpMyAdmin, it might be trying to connect via a Unix socket instead of TCP/IP. Here’s how to check:

  • Look for $cfg['Servers'][$i]['socket'] in your config.inc.php file.
  • Find MySQL’s actual socket path by running mysql_config --socket in the terminal.
  • If the paths don’t match, update the config line to the correct path, or switch to using 127.0.0.1 as the host to force a TCP/IP connection.

After trying these steps, refresh phpMyAdmin and test the connection again. If you’re still stuck, share more details about your setup (local XAMPP/WAMP, remote server, OS) and any extra error messages—this will help narrow down the issue further!

内容的提问来源于stack exchange,提问作者Sabari Kutty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:13:43