Author: Devyarn
Website: www.devyarn.com
A Windows batch script to safely sync MySQL data folder with a backup in XAMPP. It automates pre-backups, cleans old data, and restores selected files.
Use this tool only when you see the following error in XAMPP:
[mysql] Error: MySQL shutdown unexpectedly.
[mysql] This may be due to a blocked port, missing dependencies,
[mysql] improper privileges, a crash, or a shutdown by another method
[mysql] Press the Logs button to view error logs and check
[mysql] the Windows Event Viewer for more clues
[mysql] If you need more help, copy and post this
[mysql] entire log window on the forums.
- Initial Warning: Displays the MySQL shutdown error message and prompts the user to proceed.
- XAMPP Path Input: Prompts for the XAMPP root path (default:
C:\xampp
). - Pre-Backup: Creates a timestamped pre-backup of the current MySQL
data
folder (skippingibdata1
). - Folder Cleanup: Deletes folders in the
data
directory that exist in the backup. - File Cleanup: Deletes files in the
data
folder except critical system files likeibdata1
. - Restore from Backup: Copies all files and folders from the backup folder into the
data
folder. - Old Backup Cleanup: Keeps only the latest 3 pre-backups and deletes older ones automatically.
- Summary Report: Displays total deleted items, source backup folder, target data folder, and pre-backup location.
Note: All deleted items are pre-backed up, so you can restore if needed.
- Run the script.
- Read the warning and press Enter.
- Enter your XAMPP root path (or press Enter to use
C:\xampp
). - The script will automatically backup, clean, restore, and manage older pre-backups.
- Review the summary report after completion.
- Critical files like
ibdata1
are never deleted. - Ensure the backup folder contains valid MySQL database copies.
- Do not run on live production servers without testing.
- Avoid modifying system files while MySQL is running.
Explore other professional scripts at Devyarn.