XAMPP运行故障:端口修改后root用户无密码访问被拒
Hey there, let's work through this issue together. It sounds like MySQL Workbench might have altered your root user credentials or there's a mismatch between XAMPP's MySQL configuration and phpMyAdmin's settings. Here are actionable steps to resolve this:
1. Verify phpMyAdmin's Configuration
First, make sure phpMyAdmin is pointing to the correct port and using the right root credentials:
- Navigate to your XAMPP phpMyAdmin config file:
- Windows:
C:\xampp\phpMyAdmin\config.inc.php - macOS/Linux:
/opt/lampp/phpmyadmin/config.inc.php
- Windows:
- Open the file in a text editor and check these lines:
$cfg['Servers'][$i]['port'] = '3307'; // Make sure this matches your XAMPP MySQL port $cfg['Servers'][$i]['password'] = ''; // Leave empty since you never set a password $cfg['Servers'][$i]['auth_type'] = 'config'; // Skips login prompt and uses the above credentials - Save the file and restart your XAMPP MySQL and Apache services.
2. Check MySQL Root User Credentials Directly
If phpMyAdmin still errors out, let's confirm the root user's password status via the command line:
- Open the XAMPP Control Panel, click "Shell" under MySQL.
- Run this command to connect to your 3307-port MySQL instance:
mysql -u root -P 3307- If you connect successfully, the root password is indeed empty—so the issue is likely with phpMyAdmin's config.
- If you get a password prompt, MySQL Workbench did set a root password. To reset it:
- Stop the XAMPP MySQL service from the control panel.
- In the XAMPP Shell, run:
mysqld --skip-grant-tables - Open a new XAMPP Shell window and connect with:
mysql -u root -P 3307 - Run these commands to reset the root password to empty:
USE mysql; -- For MySQL 8.0+ UPDATE user SET authentication_string='' WHERE User='root' AND Host='localhost'; -- For older MySQL versions -- UPDATE user SET password=PASSWORD('') WHERE User='root' AND Host='localhost'; FLUSH PRIVILEGES; EXIT; - Close the first shell window (running
--skip-grant-tables), restart XAMPP MySQL, and try phpMyAdmin again.
3. Clean Up MySQL Workbench Residues (If Needed)
If you suspect lingering Workbench settings are causing issues:
- Uninstall MySQL Workbench via your system's app manager (Control Panel on Windows, Applications folder on macOS, package manager on Linux).
- Delete Workbench's configuration folders to remove any leftover settings:
- Windows:
C:\Users\[YourUsername]\AppData\Roaming\MySQL\Workbench - macOS:
~/Library/Application Support/MySQL/Workbench - Linux:
~/.mysql/workbench
- Windows:
- Restart your computer, then launch XAMPP and test phpMyAdmin again.
4. Ensure No Other MySQL Processes Are Running
Sometimes, a separate MySQL instance (from Workbench) might interfere. Check for running mysqld processes:
- Windows: Open Task Manager → Details tab, look for
mysqld.exeand end any that aren't part of XAMPP. - macOS/Linux: Run
ps aux | grep mysqldin the terminal, then kill any unrelated processes withkill [PID].
Let me know if any of these steps resolve your issue, or if you hit any snags along the way!
内容的提问来源于stack exchange,提问作者awow27

