What the XAMPP Error “MySQL Shutdown Unexpectedly” Is

As the name of the error implies, this is the message you’ll see if the MySQL software on your environment shuts down or ceases to function unexpectedly:

- The XAMPP error “MySQL shutdown unexpectedly”.
We say “unexpectedly”, because you can manually shut down the MySQL database software at any point. That also happens when you restart your server.

However, when the software is shut down, your website won’t be able to connect to its database. In other words, WordPress won’t work.

As you can see in the above image, XAMPP provides you with advice on troubleshooting the “MySQL shutdown unexpectedly error” right within its events log. In the next section, we’ll go into more detail on the various ways you can use to fix this issue.

How to Fix the XAMPP Error “MySQL Shutdown Unexpectedly” (3 Methods)
Typically, fixing the XAMPP error “MySQL shutdown unexpectedly” is quick and easy. Below, we’ll walk you through three fixes, starting with the simplest.

1. Run XAMPP Using Administrator Privileges
Often, XAMPP produces errors when you don’t run the software using administrator privileges. This is because its components may not be able to function or configure properly at lower permission levels.

If you’re unsure whether that’s the case with your setup, we recommend that you close XAMPP altogether, and then restart the environment as an administrator. To do so in Windows, find the folder where you installed XAMPP and locate the xampp-control file. Next, right-click on that file and select Run as administrator:
- Launching XAMPP with administrative privileges.

If you’re a macOS user, you can right-click on the folder, and then select Get Info. In the pop-up window that opens, navigate to the Sharing & Permissions section, click on the padlock icon, and enter your administrator password. Change the Read & Write permission settings to Everyone.

Once XAMPP is up and each of its components is running, MySQL should function correctly. That means your database will be accessible.

2. Restore Your Database Backup
If restarting XAMPP with administrator privileges doesn’t solve the problem with your database, the next step is to restore its backup. XAMPP automatically creates backups for your environment’s software, which you can access within the folder where you installed it.

By default, your XAMPP MySQL backup files should be under Local Disk > XAMPP > MySQL. Inside that directory, you’ll see several folders, two of which are called data and backup:
The data folder includes all of the files that your database uses. The backup folder contains a single recent copy of your MySQL.

Before you restore the backup files, use your XAMPP control panel to stop the MySQL software.

You can make a backup by clicking on the Stop button to the right of the MySQL option on the main menu:
- Using the XAMPP control panel.

Once you stop MySQL, return to XAMPP’s MySQL folder and follow these steps to restore the MySQL backup:
  1. Make a copy of the data folder.
  2. Rename this new folder copy to something like data-old. This will be your backup.
  3. Copy the contents of the backup folder into the data folder.
That’s it! To play it safe, though, we strongly recommend that you keep the data-old folder around until you make sure everything is working properly.

At this stage, you can return to the XAMPP control panel to restart MySQL, which should be running correctly now.

3. Change Your MySQL Port
One of the most common causes of the XAMPP error “MySQL shutdown unexpectedly” is another software using the port assigned to MySQL. By default, it tends to be 3306. To be certain, you can select the Netstat module from XAMPP’s control panel, right above the Shell tool:
 - Using XAMPP’s Netstat tool.

Netstat is a command line tool that can show you active connections on your network, including which ports they’re using. Once you initialize Netstat, you’ll be able to see what port each tool in your stack is using, including MySQL.

- Checking active connections using Netstat.

If a conflict with that port caused the shutdown, restoring a backup or running MySQL with administrator privileges won’t make a difference. The only way to solve this issue is to change the port that MySQL uses. Thanks to Netstat, you can see what that port is and which other ones are in use.

To do so, go ahead and stop the service, using the same process we showed you in the last section. Next, click on the Config button next to MySQLon XAMPP’s main menu, and then select the my.ini option:

Accessing MySQL’s config file.
The my.ini file contains the MySQL configuration settings. After you click on it, XAMPP will open the file using your default text editor. Once you’re in, look for the line that reads Port, which specifies the port number that MySQL uses.

Here, you can change that port number to another option that you know other programs aren’t using. In most cases, we recommend using 3307, which should be available. Save your changes and close the my.ini file.

You can then use the XAMPP control panel to restart MySQL. Hopefully, your database is now working as it should. If for some reason, XAMPP can’t connect to your database using the new port that you set, it will let you know through the control panel’s log. In that case, you might try using a different port instead.

If you use XAMPP to run WordPress locally, you may encounter the occasional error with your server’s configuration. One of the most common issues is MySQL shutting down unexpectedly.

The good news is that, if this does happen, there are three methods you can use to troubleshoot the issue:
  1. Run XAMPP using administrator privileges.
  2. Restore your database backup.
  3. Change your MySQL port.

Post a Comment