If you use a local development environment, you may run into problems that are similar to those on a live server. In some cases, your WordPress website may be unable to connect with its database because MySQL isn’t running or it shut down unexpectedly.
Depending on which local environment you use, the process of troubleshooting your MySQL database might vary a bit. With XAMPP, the process is remarkably straightforward since you get access to a control panel instead of having to rely on the command line only.
In this article, we’ll explain what XAMPP is and what the “MySQL shutdown unexpectedly” error means. Then we’ll walk you through three methods you can use to fix it. Let’s get to it!
An Introduction to XAMPP
XAMPP is a free, PHP development environment that you can use for Windows, macOS, or Linux. It is a collection of software that enables you to host websites locally by mimicking the functions of a live server:
Using XAMPP, you can install all the software you need to run WordPress locally using a single bundle, rather than setting up each element individually. Development environments differ in what software they bundle.
With XAMPP, the components that you get include:
- Apache: This is arguably the most popular web server software in the world, and it enables you to host sites.
- MariaDB: This open-source database software enables you to manage databases.
- PHP: WordPress is built on PHP, which means you need a PHP install to run the Content Management System (CMS).
- Perl: Although WordPress doesn’t use the Perl programming language, it comes as part of the XAMPP stack by default.
On top of setting up the software you need to run WordPress, XAMPP provides you with a simple control panel:
This enables you to access logs for each of XAMPP’s components. It includes an overview log that shows you everything that’s happening in the background of your environment.
However, using a local development distribution doesn’t mean your server isn’t susceptible to errors. In some cases, the software components may malfunction, such as with the XAMPP error “MySQL shutdown unexpectedly”.
What Is the XAMPP Error “MySQL Shutdown Unexpectedly”?
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:
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:
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.
You can make a backup by clicking on the Stop button to the right of the MySQL option on the main menu:
Once you stop MySQL, return to XAMPP’s MySQL folder and follow these steps to restore the MySQL backup:
- Make a copy of the data folder.
- Rename this new folder copy to something like data-old. This will be your backup.
- 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:
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.
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:
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:
- Run XAMPP using administrator privileges.
- Restore your database backup.
- Change your MySQL port.
If you enjoyed this XAMPP tutorial, be sure to check out DevKinsta as well. DevKinsta is our free local development tool that lets you quickly spin up WordPress sites with customizable PHP settings, HTTPS support, built-in email and database management, and more. DevKinsta also features full integration with MyKinsta, but you don’t have to be a Kinsta customer to integrate DevKinsta into your workflow.