Skip to content

Instantly share code, notes, and snippets.

@gildniy
Forked from josemmo/repair-mysql-data.ps1
Created April 30, 2022 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gildniy/f3d533e3620c93b64f570aba3b798814 to your computer and use it in GitHub Desktop.
Save gildniy/f3d533e3620c93b64f570aba3b798814 to your computer and use it in GitHub Desktop.
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment