XAMPP中MySQL端口被阻塞:更换端口后问题仍存在
Let me walk you through some practical, step-by-step checks to resolve this port blocking problem you’re stuck with:
1. Confirm if Port 3308 is Actually Occupied
First, we need to pinpoint exactly what’s holding onto port 3308 (if anything):
- Windows: Open Command Prompt as Administrator and run:
Note the PID number in the last column, then open Task Manager > Details tab, find that PID, and end the process. It’s often a leftover MariaDB/MySQL service from your messy first installation that didn’t fully shut down.netstat -ano | findstr :3308 - macOS/Linux: Open Terminal and run:
Uselsof -i :3308kill -9 <PID>to force-stop the conflicting process.
2. Double-Check All MySQL Port Configurations
Make sure your port change is applied everywhere it needs to be:
- Open the
my.ini(ormy.cnf) file in your XAMPP MySQL directory. Confirm you’ve set:
Save and close the file.port=3308 bind-address=127.0.0.1 - Launch the XAMPP Control Panel:
- Click the "Config" button next to MySQL, select "my.ini" to re-verify the port setting.
- Go to "Service and Port Settings" > "MySQL" tab, ensure the port is set to 3308, save changes, then restart the XAMPP MySQL service.
3. Clean Up Leftover System Services (Windows Only)
Previous MySQL/MariaDB installs might have left behind system services that are still hogging resources:
- Press
Win + R, typeservices.msc, and hit Enter. - Look for any services named "MySQL" or "MariaDB". If found, right-click to stop them, set their startup type to "Disabled", and even delete them via admin Command Prompt:
sc delete <ServiceName>
Restart your computer to clear any lingering processes, then try starting XAMPP’s MySQL again.
4. Test a Direct Connection to Port 3308
Narrow down the issue by connecting directly via the command line:
- Open XAMPP’s Shell (click the "Shell" button in the control panel) and run:
mysql -u root -P 3308 -p
A "Connection refused" error means MySQL isn’t listening on 3308 at all; a timeout points to firewall interference.
5. Check Firewall and Antivirus Settings
Windows Firewall or third-party antivirus often blocks new ports:
- Temporarily disable your firewall/antivirus and try starting MySQL again. If it works, add an inbound/outbound rule for port 3308 to allow MySQL traffic.
- Ensure the rule covers both TCP and UDP protocols, and explicitly includes the XAMPP MySQL executable (
mysqld.exeinxampp/mysql/bin).
内容的提问来源于stack exchange,提问作者FerrisDale

