Ren Stanforth

Software Engineer

Ren Stanforth

Software Engineer

Blog Post

Error: MySQL Shutdown Unexpectedly

March 12, 2022 Journal, Tutorials
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:

XAMPP Control Panel Showing Error
You might’ve encountered this error too.
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?

1. Rename xampp/mysql/data folder first. Name it something like data_backup.

GIF of renaming folder

2. Then copy xampp/mysql/backup folder and name it as xampp/mysql/data. This will serve as your new data folder.

GIF showing copying of backup 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!

GIF of copying important file

5. Start the MySQL server in the XAMPP application. If it doesn’t start, run the application as administrator.

GIF showing XAMPP Control Panel running

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:

  1. Go to localhost/phpMyAdmin.
  2. Click the database table mysql.
  3. Check all of the tables.
  4. Choose With selected: choose Repair table which automatically repairs the table for you after clicking.
Repair mysql database tables

You can now add database users, then connect your local sites to the database.


Resources:

Stackoverflow

Youtube

Write a comment