Error: MySQL Shutdown Unexpectedly
What gives me a mini-heart attack when I’m developing locally is having database error/s upon starting my dailies at work.
Number 0 culprit of this is the MySQL server not able to start. Why is this a suspect of mine? That’s because it was working before, and I have the correct database credentials.
When I checked my XAMPP control panel, I was greeted with this error:
Error: MySQL shutdown unexpectedly. This may be due to a blocked port, missing dependencies, improper privileges, a crash, or a shutdown by another method. Press the Logs button to view error logs and check the Windows Event Viewer for more clues If you need more help, copy and post this entire log window on the forums
For my side, this was caused by the sudden shutdown of the application. Always remember to shut it down properly next time!
How to fix this error?
xampp/mysql/data folder first. Name it something like
2. Then copy
xampp/mysql/backup folder and name it as
xampp/mysql/data. This will serve as your new data folder.
3. Copy all of the subfolders from
data_backup folder to the new data folder. Make sure not to include the following folders: mysql, performance_schema, phpmyadmin, and test.
4. In your data_backup folder, there is a file named ibdata1. Copy this file to the new
xampp/mysql/data folder. Replace the ibdata1 that was copied from
xampp/mysql/backup. This file is important, so better NOT DELETE it at any cost!
5. Start the MySQL server in the XAMPP application. If it doesn’t start, run the application as administrator.
BUT WAIT, THERE’S MORE
The steps above will only copy the databases that you’ve created. This does not include the user accounts you’ve set in the mysql database. You will need to add those users again.
While I was about to add users, I have encountered the error #1034: Index for table ‘db’ is corrupt; try to repair it. To repair, do the following:
- Go to localhost/phpMyAdmin.
- Click the database table mysql.
- Check all of the tables.
- Choose With selected: choose Repair table which automatically repairs the table for you after clicking.
You can now add database users, then connect your local sites to the database.