When you’re running XAMPP on your local machine, you’re likely to face the error: MySQL shutdown unexpectedly. This error prevents the MSQL server from starting, something that can hamper your project.
12:21:29 [mysql] Error: MySQL shutdown unexpectedly.
12:21:29 [mysql] This may be due to a blocked port, missing dependencies,
12:21:29 [mysql] improper privileges, a crash, or a shutdown by another method.
12:21:29 [mysql] Press the Logs button to view error logs and check
12:21:29 [mysql] the Windows Event Viewer for more clues
12:21:29 [mysql] If you need more help, copy and post this
12:21:29 [mysql] entire log window on the forums
12:21:33 [mysql] Attempting to start MySQL app...
12:21:33 [mysql] Status change detected: running
12:21:34 [mysql] Status change detected: stopped
To fix the Error: MySQL shutdown unexpectedly, we need to follow these steps:
Navigate to the MYSQL subdirectory
The MYSQL subdirectory is located inside the XAMPP directory under the following path in Windows:
C:\xampp\mysql
Make a copy of the data subdirectory
While inside the MYSQL subdirectory, our main attention should be put on the data subdirectory:
The clone copy of the data subdirectory can be made by right-clicking on it, copying, and pasting.
Enter into the data subdirectory
Now that we’ve backed up the data folder, we need to click on it and go inside; This is what you gonna see:
Delete all the files and folders except your app database subdirectory and the ibdata1 file. In this example, my app database subdirectory is called your_App_db. In your case, this could be different so you have to be sure as deleting this subdirectory could mean that you’re going to lose your application database files.
Whatever is highlighted in this screenshot shouldn’t be deleted but remove everything else:
Go to the Backup Subdirectory in the MYSQL directory
We need to replace the deleted files with the ones inside the backup subdirectory, which is located under this path:
C:\xampp\mysql
This is the folder we’re talking about:
In the backup subdirectory, you’re going to select and copy everything in there and only leave out the ibdata1 file. To be precise, don’t copy the ibdata1 file but copy everything else:
It’s important to note that the backup subdirectory we’re talking about is not the clone copy of the data subdirectory we made earlier. The backup subdirectory is part of the default XAMPP default directory structure.
Paste the copied files into the data subdirectory
Now, you need to go back to the data subdirectory under this path:
C:\xampp\mysql\data
Paste everything you’ve copied from the backup subdirectory.
Start the MYSQL Server
You can now start the MYSQL Server using the XAMPP Control Panel, and everything will normally without facing the error again