Skip to content

Instantly share code, notes, and snippets.

Created August 28, 2020 18:48
Star You must be signed in to star a gist
What would you like to do?
Repair MySQL data directory (for XAMPP)
# Based on this answer:
# 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"
Copy link


Copy link

Thanks for the script. It's working fine

This is the way to execute the script

PowerShell.exe -ExecutionPolicy UnRestricted -File repair-mysql-data.ps1

Copy link


Copy link

Saved my day! Thanks!

Copy link

Você salvou minha vida cara!(You saved my life man!) 🎉

Copy link

Excellent. however, since MySQL shuts down often and we need to run this script frequently to fix the issue, is there a line we can add to the beginning of the script, to delete data_old to make way for the new data_old (new backup)? as @grandeljay points out

Copy link

niglng commented Oct 21, 2021

This is just so lovely

Copy link

So Amazing!!!!!!

Copy link

how to use this bloc of code

Copy link

bmrafiq commented Jan 11, 2022


Copy link

@safirbltr Go to xampp directly, then go to mysql and then open PowerShell there and simply paste this code.

Copy link


Copy link

Amazing! Thanks so much.

Copy link

thanks man you saved my precious time

Copy link

thank you saved my time

Copy link

prathu9 commented May 15, 2022

thank you.

Copy link

Still helpful even now. Thank you so much!

Copy link

irkha commented Jun 22, 2022

The best solution ever. it solves the problem in seconds
Thanks a lot

Copy link

This works! But for time being. MySQL started crashing again. Not a permanent solution.

Copy link

Thank you very much!!

Copy link

Rettend commented Sep 29, 2022


Copy link

how do we exactly run this script?

Copy link

thank you.

Copy link

To-heeb commented Dec 4, 2022

How to run this script

  1. Create a file with the extension ".ps1" in your mysql directory in your xampp folder e.g(repair-mysql-data.ps1).

  2. Open the file and paste the above commands in it.

  3. Then open the mysql folder in your powershell terminal( left click then you see ) this ⬇️

  4. Then you see this ⬇️

  5. 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)⬇️

  6. Another way to get it done

Copy link

Waheire commented Feb 2, 2023

Great! worked!, thank you!

Copy link

cartzedan commented Apr 24, 2023

Great work. This works perfectly without errors or stress.

Copy link


Copy link

DKVI commented Aug 2, 2023

I confirm it still works!

Copy link

This still works, thank you

Copy link

thank you very much it still works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment