XAMPP “MySQL shutdown unexpectedly”: the fix
“Error: MySQL shutdown unexpectedly. This may be due to a blocked port, missing dependencies, improper privileges, a crash, or a shutdown by another method.” In practice it is usually one of two things: another program holds port 3306, or the MariaDB data files were left inconsistent after Windows or XAMPP closed while MySQL was running. Here is how to tell which, how to get your data back, and how to move it somewhere maintained.
- Platform
- Windows 10/11 with XAMPP in C:\xampp
- Time
- About 15 minutes
- You need
- XAMPP installed in C:\xampp (adjust the paths if yours is elsewhere)
- Enough free disk space to copy the mysql\data folder once
XAMPP paths are for the default C:\xampp install; EnvKit steps written against 0.33.0-beta.25. Checked 2026-09-18.
Step 1: Read the real error
In the XAMPP Control Panel, click Logs next to MySQL and open
mysql_error.log(it lives inC:\xampp\mysql\data). The last lines before the shutdown tell you which case you are in.Step 2: Rule out a port conflict
If the log says the port is in use (“Do you already have another mysqld server running on port: 3306?”), find the program holding it. A MySQL Windows service from another installer is the usual culprit; stop it in services.msc, or change
port=in XAMPP’smy.ini.Command Prompt netstat -ano | findstr :3306 tasklist /FI "PID eq 1234"Step 3: Back up the data folder
Before changing anything, copy
C:\xampp\mysql\datasomewhere safe. Every step below is reversible as long as this copy exists.Step 4: Rebuild the data folder from XAMPP’s backup
Rename
C:\xampp\mysql\datatodata_old. Create a new, emptydatafolder and copy everything fromC:\xampp\mysql\backupinto it.From
data_old, copy each of your own database folders intodata: every folder exceptmysql,performance_schemaandphpmyadmin. Then copydata_old\ibdata1intodata, replacing the one there. Start MySQL from the Control Panel.Step 5: Export your databases
Once MySQL starts, export every database you care about, from phpMyAdmin (Export → SQL) or with
mysqldump. Keep these dumps whatever you do next: they are the only backup that works across MySQL versions and tools.Command Prompt C:\xampp\mysql\bin\mysqldump -u root --databases mydb > mydb.sqlStep 6: Move to a maintained stack
If this keeps happening, move off XAMPP. Stop XAMPP’s Apache and MySQL first so the two do not fight over ports 80, 443 and 3306, then install EnvKit.
Or install from the terminalirm https://envkit.net/install.ps1?c=guide-xampp-mysql-shutdown-unexpectedly | iexStep 7: Import your databases and projects into EnvKit
On the first launch keep Nginx (or pick Apache if your projects rely on .htaccess), choose Start fresh, select Laravel / PHP and click Install all. Services → MySQL also lists MariaDB versions, the closest match to what XAMPP ships.
On the Databases page create each database, click Open phpMyAdmin and import your
.sqldumps. Then add each project with Sites → New project → Add existing project: it is served where it is, at https://<folder>.test with a trusted certificate.
If something goes wrong
- MySQL still stops after the rebuild
- Check
mysql_error.logagain. A line about a missing or corrupt table points at that table’s folder; restore it from your backup copy, or drop it and re-import it from a dump. - When EnvKit’s MySQL will not start
- The error shows the reason from mysqld’s own log with a hint, and Services → MySQL → Diagnose & repair names the process holding the port and offers to stop it.
- Several projects need different MySQL versions
- EnvKit runs other installed MySQL or MariaDB versions next to the active one, each on its own port. Start them from the MySQL / MariaDB versions list on the MySQL page.