How do i start mysql in xampp?

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:

How do i start mysql in xampp?
The XAMPP website.

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:

How do i start mysql in xampp?
The XAMPP 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 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:

How do i start mysql in xampp?
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:

How do i start mysql in xampp?
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.

Want to know how we increased our traffic over 1000%?

Join 20,000+ others who get our weekly newsletter with insider WordPress tips!

Subscribe Now

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:

How do i start mysql in xampp?
XAMPP’s MySQL directory.

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:

How do i start mysql in xampp?
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:

How do i start mysql in xampp?
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.

How do i start mysql in xampp?
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:

How do i start mysql in xampp?
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.

Summary

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.

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.


Save time, costs and maximize site performance with:

  • Instant help from WordPress hosting experts, 24/7.
  • Cloudflare Enterprise integration.
  • Global audience reach with 35 data centers worldwide.
  • Optimization with our built-in Application Performance Monitoring.

All of that and much more, in one plan with no long-term contracts, assisted migrations, and a 30-day-money-back-guarantee. Check out our plans or talk to sales to find the plan that’s right for you.

How do I open MySQL in XAMPP?

To access MySQL in Windows you need to install the XAMPP..
Open the XAMPP Control Panel and start MySQL..
Now go to the command prompt and open C:\>cd xampp C:\xampp>cd MySQL C:\xampp\mysql>cd bin C:\xampp\mysql\bin>mysql -h localhost -u root..

Why MySQL is not start in XAMPP?

Fixing the MySQL server not starting in XAMPP is done by reverting back the data files pre-issue. Navigate to your XAMPP MySQL directory ( C:\xampp\mysql ). Create a new folder called FIX_BACKUP . Copy C:\xampp\mysql\backup and C:\xampp\mysql\data into C:\xampp\mysql\FIX_BACKUP .

How do I start MySQL server?

Windows – Start and Stop Server.
Open 'Run' Window by using Win key + R..
Type 'services.msc'.
Now search for MySQL service based on the version that is installed..
Click on 'stop', 'start' or 'restart' the service option..

How do I run MySQL on localhost?

Go ahead and open MySQL Workbench and let's connect to this new local server. Click on the “New Connection” icon and leave everything default, except the “Connection Name,” here enter localhost . Double click on the new connection and enter the password you created during installation. Voila!