Skip to content

Instantly share code, notes, and snippets.

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

Thanks!

@mintbird
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

@vinnyCalixto
Copy link

BRILLIANT!!! TKS A LOT

@souvik21
Copy link

Saved my day! Thanks!

@fausantosdev
Copy link

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

@Musafa-Musafa
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

@niglng
Copy link

niglng commented Oct 21, 2021

This is just so lovely

@johnabednego
Copy link

So Amazing!!!!!!

@safirbltr
Copy link

how to use this bloc of code

@bmrafiq
Copy link

bmrafiq commented Jan 11, 2022

Awesome

@SannanOfficial
Copy link

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

@AdrianGS8E
Copy link

Thanks!!!!

@sarah-browning
Copy link

Amazing! Thanks so much.

@DinithKumudika
Copy link

thanks man you saved my precious time

@ashenthiwanka99
Copy link

thank you saved my time

@prathu9
Copy link

prathu9 commented May 15, 2022

thank you.

@Pseudoman21
Copy link

Still helpful even now. Thank you so much!

@irkha
Copy link

irkha commented Jun 22, 2022

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

@theweirdgenius
Copy link

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

@vasquezdavidd
Copy link

Thank you very much!!

@Rettend
Copy link

Rettend commented Sep 29, 2022

Ty!

@anasriaz786
Copy link

how do we exactly run this script?

@akashsinghtkd
Copy link

thank you.

@To-heeb
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 ⬇️
    image

  4. Then you see this ⬇️
    image

  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)⬇️
    image

  6. Another way to get it done

@Waheire
Copy link

Waheire commented Feb 2, 2023

Great! worked!, thank you!

@cartzedan
Copy link

cartzedan commented Apr 24, 2023

Great work. This works perfectly without errors or stress.

@MarioSwitch
Copy link

Perfect!

@DKVI
Copy link

DKVI commented Aug 2, 2023

I confirm it still works!

@ucheohams
Copy link

This still works, thank you

@rbtarthur
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