Asad Ali

[Solved] Error: “MySQL Shutdown Unexpectedly” in XAMPP (2 methods)

If you use a local development environment, you may encounter issues identical to those seen on a live server. Because MySQL isn’t operational or shut down unexpectedly, your WordPress website may be unable to connect to its database in some cases.

The procedure of troubleshooting your MySQL database may differ slightly depending on which local environment you choose. The procedure is very simple with XAMPP since you have access to a control panel instead of having to rely only on the command – line interface.

In this article, I’ll guide you step by step procedure on how you can fix this MySQL Shutdown Unexpectedly error.

Table of Contents

If you suddenly start getting this error Error: MySQL shutdown unexpectedly

There may be mainly 2 reasons for that:

  1. The MySQL 3306 port is being used by another service or program. To get rid of this, we can serve MySQL on another port like 3307.
  2. There may be some MySQL specific files that are not saved properly before shutting down your computer. Don’t worry we can make use of backup to restore our databases in working state.

Method 1: Changing MySQL port

Step 1: To change your MySQL port, open you XAMPP Control Panel and click on Config button opposite MySQL.

Step 2: A dropdown item ‘my.ini’ will be displayed. Open that file.

Step 3: Change MySQL port from 3306 to 3307 on two lines as shown in below screenshot.

Step 4: Restart MySQL after, saving and closing the file.

Step 5: If you see MySQL in green highlight, then congratulations. Your MySQL is now working properly and you can now work with your databases.

Method 2: Changing MySQL port

If the method 1 doesn’t work. You need to go through the below process.

Step 1: Go to your XAMPP installation directory. Usually it’s in C:\xampp. From there you will need to go to a folder named ‘mysql’.

Step 2: Here rename the ‘data’ folder to (data-old). Then make a new folder named data and copy the contents of backup in it.

You also need to copy your databases. There is each separate folder named by your database in data-old folder.

Step 3: Copy all the database folders you want to restore from data-old folder to newly created data folder.