Table of Contents
This article will show you how to Fix ‘MySQL Shutdown Unexpectedly’ issue. “Error: MySQL shutdown unexpectedly” is a message that users of the MySQL platform see. Some of the reasons for this error are problems with the database and files that are not in good shape. If you use a local development environment, you may run into problems that are the same as those on a live server. Your WordPress site might not be able to connect to its database if MySQL isn’t running or if it shuts down unexpectedly. If you want to know more information about this Visit Official Microsoft Support site.
Depending on your local environment, the way you figure out what’s wrong with your MySQL database might be a little different. With XAMPP, the process is very easy because you can use a control panel instead of just the command line. Some XAMPP users can’t get MySQL to run. They say that every time they start MySQL in XAMPP, they get an error message that says “MySQL Shutdown Unexpectedly issue” Most of the time, this problem is caused by XAMPP database files that are broken. If you’re having problems like this with MySQL, the tips in this post might help you Fix ‘MySQL Shutdown Unexpectedly’ issue.
Change Client and Server Ports
In some cases, the problem could also be due to the ports that the MySQL server is using. This can happen when MySQL server tries to use ports that are already being used by another service or are blocked on your system. To fix the problem, you will need to edit the my.ini file and change the client and server ports. Follow the steps to Fix ‘MySQL Shutdown Unexpectedly’ issue:
- Open Windows Explorer and go to the directory where XAMPP was installed.
- Find the mysql > bin folder inside the xampp folder.
- Then, open the my.ini file in the bin folder using a notepad. To do this, right-click on the file and choose Open with > Notepad from the menu.
- Once the my.ini file is open, look for the client port and server port, as shown in the picture below, and change them.
- Save the file, and then open XAMPP again.
- Lastly, try starting the MySQL server to see if the error is still there.
Repair MySQL Database with Shell
In addition to the above method, you can also try to fix the problem by using the Shell in the XAMPP Control Panel to try to fix the mysql server. This is the right solution for you if you want to use the command line more. Here, we’ll first try to open the mysql server using the shell. Then, in a different shell window, we’ll try to fix the mysql database. Follow the steps below:
- First, start the XAMPP Control Panel.
- From the XAMPP Control Panel, click on the Shell button to open a shell.
- Enter the following command to start mysql once the shell is open:
- mysqld –console –skip-grant-tables –skip-external-locking
- After that, go to the control panel and open another shell window.
- To fix the database, copy and paste the following command into the new shell window:
- mysqlcheck -r –databases mysql –use-frm
- Once you’ve done that, stop mysql from the first shell window, and then close both shell windows.
- After that, you can try to see if the problem is still there by restarting mysql.
Stop MySQL Service
As it turns out, the MySQL service can sometimes also be to blame for the problem. This happens when the MySQL service is already running when you try to start the mysql server through the XAMPP Control Panel. In this case, you will need to stop the MySQL service from the Windows Services window. When your system’s services aren’t working right, they can cause problems like not being able to connect to a Windows service and more. However, this isn’t really anything to worry about. So, if you want to stop the service, just follow the steps below:
- Press the Windows key and the R key on your keyboard to bring up the Run box.
- In the box that says “Run,” type “services.msc” and hit “Enter.”
- In the Services window that opens, you can see a list of all the services on your system.
- Find the MySQL service in the list of services and right-click it. Choose Stop from the drop-down menu.
- You can also just click the Stop button on the left side after highlighting the MySQL service.
- Wait until the service is finished. After that, try manually starting the MySQL server from the XAMPP Control Panel to see if the problem still happens.
Use MySQL Backup Folder
When you get the error message “MySQL shut down unexpectedly,” you will need to use the backup files that are in the backup folder of the mysql directory. This is part of XAMPP, and the process is simple and easy to understand. Before we move on, you should make a backup of your database so that you don’t lose any of your data in case something goes wrong.
In this method, we’ll just copy the contents of the backup folder into the data folder inside the mysql directory. You won’t lose your data if you do this, so don’t worry about that. So, to do this, follow the steps below:
- First, make sure that the XAMPP web server is completely shut down.
- Once the web server is shut down, go to the folder where xampp is installed. By default, xampp is located at “C:xampp.”
- Open the mysql folder inside the xampp folder.
- Find the data folder in the mysql folder and change its name to data_old.
- Once you’ve done that, right-click and choose New > Folder from the drop-down menu in the mysql directory to make a new folder. Give this new folder the name “data.”
- Open the backup folder after you’ve made the data folder. Copy the contents of the backup folder and paste them into the data folder that you just made.
- Once you’ve done that, go back to the data_old folder and copy your database folders from there to the new data folder.
- After that, copy the ibdata1 file from the data_old folder and replace it with the one in the new data folder.
- Now that you’ve done all of that, you can run XAMPP as an administrator. Once the XAMPP Control Panel is open, try starting the MySQL server to see if the problem is still there.
When you try to close xampp, you may get this error: Cannot create file xampp-control.ini. This is because the file is corrupted. Access is denied, you need to fix this error first so that it doesn’t happen again. The error “MySQL shut down unexpectedly,” which is caused by a damaged file, won’t happen again if you fix the problem with “Cannot create file xampp-control.ini.” Error: “Access is not allowed.” Let’s talk about the “Error: Cannot create file xampp-control.ini” message. Access is denied” error first to stop the “error: MySQL shut down unexpectedly” error from happening again.
FAQs
The most likely reason why the MySQL service in XAMPP can’t start is that port 3306 is already being used by another program on your computer. When XAMPP is started, the MySQL service automatically connects to port 3306. It can only do this if another program is not already using it.
Other things that can cause this error are corrupted files, missing files, and changes to the port. When you run MySQL on a web server, corrupted files in the mysql/data folder cause MySQL to shut down.