DEV Community

Cover image for Fix: MySQL "Shutdown Unexpectedly" Error in XAMPP (Restore Your Databases)
Emmanuel Mingala
Emmanuel Mingala

Posted on

Fix: MySQL "Shutdown Unexpectedly" Error in XAMPP (Restore Your Databases)

Error: MySQL Shutdown Unexpectedly<br>
Image

If you're using XAMPP and suddenly encounter the "MySQL shutdown
unexpectedly"
error, you're not alone. This is a common issue that
often happens after reinstalling XAMPP or when MySQL files become
corrupted.

Fortunately, in most cases your databases are still recoverable.

In this guide, we'll restore MySQL by rebuilding the data directory
using the /backup folder while keeping your existing databases
intact.


Step 1: Open the MySQL Folder

Navigate to your XAMPP installation directory and open:

/xampp/mysql
Enter fullscreen mode Exit fullscreen mode

STEP 1: Open<br>
/xampp/mysql

Inside this directory, you will find two important folders:

  • /backup
  • /data

These folders will be used to repair the corrupted MySQL installation.


Step 2: Create a Backup of the /data Folder

Copy the /data folder and rename the copy to:

data - Copy
Enter fullscreen mode Exit fullscreen mode

STEP 2: Copy the  raw `/data` endraw  folder and rename it as<br>
 raw `

This copy will serve as a temporary backup so we can restore your
existing databases later.


Step 3: Delete the Contents of the /data Folder

Open the original /data folder and delete all its contents.

STEP 3: Delete the content of your  raw `/data` endraw <br>
folder.

This removes the corrupted MySQL files that are causing the server
to fail.


Step 4: Restore Default MySQL Files

Open the /backup folder.

STEP 4: Copy the contents of the  raw `/backup` endraw  folder in the  raw `/data` endraw <br>
folder.

Select all files inside /backup and copy them.

STEP 4: Copy the contents of the  raw `/backup` endraw  folder in the  raw `/data` endraw <br>
folder.

Paste them into the /data folder.

This restores the default MySQL system files needed for the server
to run.


Step 5: Restore Your Databases

Now open the folder:

/data - Copy
Enter fullscreen mode Exit fullscreen mode

STEP 5: Copy the databases from  raw `/data - Copy` endraw  to<br>
 raw `/data` endraw

Copy your database folders into the /data folder.

⚠️ Important: Do not copy the following folders:

  • /mysql
  • /performance_schema
  • /phpmyadmin
  • /test

These are system folders already restored from the /backup directory.

STEP 5: Copy the databases from  raw `/data - Copy` endraw  to<br>
 raw `/data` endraw

Paste your database folders into the /data directory.


Step 6: Restore the ibdata1 File

Inside the /data - Copy folder, locate the file:

ibdata1
Enter fullscreen mode Exit fullscreen mode

STEP 6: Copy the  raw `ibdata1` endraw  file from  raw `/data - Copy` endraw  folder and replace<br>
the one in the  raw `/data` endraw <br>
folder.

Copy this file.

STEP 6: Copy the  raw `ibdata1` endraw  file from  raw `/data - Copy` endraw  folder and replace<br>
the one in the  raw `/data` endraw <br>
folder.

Paste it into the /data folder and replace the existing file.

This step restores the InnoDB tablespace, which is required for many
MySQL databases.


Step 7: Start MySQL in XAMPP

Return to the XAMPP Control Panel and start the MySQL server.

Error fixed<br>
image

If all steps were completed correctly:

  • The MySQL error should be resolved
  • Your databases should be restored
  • The server should start normally

Final Notes

This issue usually happens because:

  • MySQL was force closed
  • XAMPP was reinstalled
  • Files inside the /data folder became corrupted

Using the /backup folder allows us to rebuild MySQL's system files
while preserving our existing databases.


Thanks for Reading

If you found this guide helpful, feel free to check out more of my
content.

You can also visit my portfolio to see more projects and blogs:

🌐 https://emmandev.site

Top comments (0)