-
-
Save josemmo/24e35f2b4984a4370ce2c164f5956437 to your computer and use it in GitHub Desktop.
# Based on this answer: https://stackoverflow.com/a/61859561/1956278 | |
# Backup old data | |
Rename-Item -Path "./data" -NewName "./data_old" | |
# Create new data directory | |
Copy-Item -Path "./backup" -Destination "./data" -Recurse | |
Remove-Item "./data/test" -Recurse | |
$dbPaths = Get-ChildItem -Path "./data_old" -Exclude ('mysql', 'performance_schema', 'phpmyadmin') -Recurse -Directory | |
Copy-Item -Path $dbPaths.FullName -Destination "./data" -Recurse | |
Copy-Item -Path "./data_old/ibdata1" -Destination "./data/ibdata1" | |
# Notify user | |
Write-Host "Finished repairing MySQL data" | |
Write-Host "Previous data is located at ./data_old" |
Still helpful even now. Thank you so much!
The best solution ever. it solves the problem in seconds
Thanks a lot
This works! But for time being. MySQL started crashing again. Not a permanent solution.
Thank you very much!!
Ty!
how do we exactly run this script?
thank you.
How to run this script
-
Create a file with the extension ".ps1" in your mysql directory in your xampp folder e.g(repair-mysql-data.ps1).
-
Open the file and paste the above commands in it.
-
Then open the mysql folder in your powershell terminal( left click then you see ) this ⬇️
-
After that run "PowerShell.exe -ExecutionPolicy UnRestricted -File repair-mysql-data.ps1" (your can always replace the name with whatever you have named the script)⬇️
Great! worked!, thank you!
Great work. This works perfectly without errors or stress.
Perfect!
I confirm it still works!
This still works, thank you
thank you very much it still works!
Saved me! Thank you sooooooo much!
Thank you!
you can add a line at the beginning of the script to delete the existing "data_old" directory before creating a new backup.
# Delete existing data_old directory
Remove-Item -Path "./data_old" -Recurse -Force
Amazing ...
It's just awesome! Thanks very much!
Marvelous! Works beautifully.
thanks! as @Chanaka-J suggests adding that line helps in case you have to run it more than once
Thank you a thousand times.
This is amazing. Thank you!
Kudos. You're the best !
Golden!
Thank you guise, this has been such an annoying beast that comes around more than once. Interesting though this has been on the books for 4 years now and still going strong.
you can add a line at the beginning of the script to delete the existing "data_old" directory before creating a new backup.
# Delete existing data_old directory Remove-Item -Path "./data_old" -Recurse -Force
Thank you all!
Thanks
Thank you!
If you get error as I did about directories not existing, change the file to this, and if paths are different change the location of directories to your absolute path:
Based on this answer: https://stackoverflow.com/a/61859561/1956278
Backup old data
Rename-Item -Path "C:/xampp/mysql/data" -NewName "C:/xampp/mysql/data_old"
Create new data directory
Copy-Item -Path "C:/xampp/mysql/backup" -Destination "C:/xampp/mysql/data" -Recurse
Remove-Item "C:/xampp/mysql/data/test" -Recurse
$dbPaths = Get-ChildItem -Path "C:/xampp/mysql/data_old" -Exclude ('mysql', 'performance_schema', 'phpmyadmin') -Recurse -Directory
Copy-Item -Path $dbPaths.FullName -Destination "C:/xampp/mysql/data" -Recurse
Copy-Item -Path "C:/xampp/mysql/data_old/ibdata1" -Destination "C:/xampp/mysql/data/ibdata1"
Notify user
Write-Host "Finished repairing MySQL data"
Write-Host "Previous data is located at C:/xampp/mysql/data_old"
thank you.