If you're using XAMPP and suddenly encounter the "MySQL shutdown
unexpectedly" error, you're not alone. This is a common issue that
often happens after reinstalling XAMPP or when MySQL files become
corrupted.
Fortunately, in most cases your databases are still recoverable.
In this guide, we'll restore MySQL by rebuilding the data directory
using the /backup folder while keeping your existing databases
intact.
Step 1: Open the MySQL Folder
Navigate to your XAMPP installation directory and open:
/xampp/mysql
Inside this directory, you will find two important folders:
-
/backup -
/data
These folders will be used to repair the corrupted MySQL installation.
Step 2: Create a Backup of the /data Folder
Copy the /data folder and rename the copy to:
data - Copy
This copy will serve as a temporary backup so we can restore your
existing databases later.
Step 3: Delete the Contents of the /data Folder
Open the original /data folder and delete all its contents.
This removes the corrupted MySQL files that are causing the server
to fail.
Step 4: Restore Default MySQL Files
Open the /backup folder.
Select all files inside /backup and copy them.
Paste them into the /data folder.
This restores the default MySQL system files needed for the server
to run.
Step 5: Restore Your Databases
Now open the folder:
/data - Copy
Copy your database folders into the /data folder.
β οΈ Important: Do not copy the following folders:
-
/mysql -
/performance_schema -
/phpmyadmin -
/test
These are system folders already restored from the /backup directory.
Paste your database folders into the /data directory.
Step 6: Restore the ibdata1 File
Inside the /data - Copy folder, locate the file:
ibdata1
Copy this file.
Paste it into the /data folder and replace the existing file.
This step restores the InnoDB tablespace, which is required for many
MySQL databases.
Step 7: Start MySQL in XAMPP
Return to the XAMPP Control Panel and start the MySQL server.
If all steps were completed correctly:
- The MySQL error should be resolved
- Your databases should be restored
- The server should start normally
Final Notes
This issue usually happens because:
- MySQL was force closed
- XAMPP was reinstalled
- Files inside the
/datafolder became corrupted
Using the /backup folder allows us to rebuild MySQL's system files
while preserving our existing databases.
Thanks for Reading
If you found this guide helpful, feel free to check out more of my
content.
You can also visit my portfolio to see more projects and blogs:











Top comments (0)