Install, Start, Stop, and Uninstall MySQL Service on Windows
If you use PHP and MySQL every time, every day, you will definitely encounter this unpleasant routine: turn on and turn off the Apache dan MySQL server manually.
It is like repeating trivial job again and again, so it will save our time if the server runs automatically, right? there many solutions out there such as creating auto start file.
However, the best solution so far is to use a service, so let’s now discuss how to install MySQL service on windows.
The same thing has also happened to Apache, so if you are in the same case, you can refer to this tutorial: Install, Start, Stop, Uninstall Apache Service on Windows.
Note that in order to be able to install the service, we should run the command prompt as Administrator.
The shortest way is by clicking on the windows start menu then type cmd, on the “Command Prompt” application file that appears on the top, right click and clicks Run as Administrator.
The Command Prompt application file (cmd(dot)exe file) can also be found in Windows system folder, usually in C:\Windows\System32.
I. Install MySQL Service on Windows Using Command Prompt
In the command prompt window, the default cursor is in the c:\windows\system32, navigate to your bin directory within MySQL directory, for instance as I have xampp installed on E drive, so my
bin
directory is in E:\xampp\mysql\bin. Next, let’s install MySQL service by running the following command:mysqld --install
The complete working command as shown bellow:
The image above informs that MySQL service is successfully installed.
Installing using a custom service name
It is possible to install MySQL service using your own name, here is this command:
mysqld --install "Your Service Name"
For instance, I’ll install mysql service using name: “MySQL – PHP 5.6”, here is the working command:
II. How to start MySQL Service on Windows Using Command Prompt
Now you successfully install MySQL service on Windows, but you’ll find that it won’t work, as it should be started manually or wait until the windows restarted, so now we want to start the service manually, simply use this command:
net start mysql
Things little differs if you install the service using custom service name as you should determine the name in the command, it would be as follows:
net start "Your Service Name"
As instance, continuing from the previous example, now we’ll start the service (named “MySQL – PHP 5.6”)
If everything ok, then the MySQL service will run correctly and no error message will be reported (like the picture above). In addition, the following figure shows that an error has occurred:
It reported that the system couldn’t find the “MySQL – PHP 5.5” service (it should be PHP 5.6)
Stopping the MySQL service
If you want to stop the service, Fortunately, run the following command:
net stop mysql
Same as previous, it will little differ when you use a custom service name, as you should determine the name in the command, it would be:
net stop "Your Service Name"
Continuing from the previous example, the following figure shows the stopping service:
Restarting the MySQL service
How to restart mysql service? restarting MySQL service need a little workaround as we don’t able t0 use the restart keyword. We need to combine the stop and start to do this task:
net stop mysql & net start mysql
Again, when you use a custom name while installing the service, you should determine the name in the command:
net stop "Your Service Name" & net start "Your Service Name"
As instance, we’ll restart our “MySQL 5.6″ service as follow:
III. How to Uninstall MySQL Service on Windows Using Command Prompt
Suppose that the things are changed and we the service need to be removed/uninstalled, then just simply run the following command:
mysqld --remove
Like the previous command, if you use a custom service name then you have to determine the service name, as follows:
mysqld --remove "Your Service Name"
Note: before uninstalling the service, we must stop the service.
For instance, let’s remove the “MySQL 5.6” service that we have installed before.
done, the service was successfully removed from our system.
IV. Additional Note
As we now that all above commands will modify service in our windows system, probably you may want to know what is happened behind, rather than just run this and that command.
Fortunately windows provide a tool which allows us to access their servicess, it named Services.msc.
As a file system, it wouldn’t visible in the windows start menu, instead, you can run it by clicking on Windows start menu and type “services” without quotes, then click on the Services.msc that appears in the search box.
Alternatively, you can also open this file through Administrative Tools by navigating to: Start » Control Panel » System and Security » Administrative Tools.
Maybe it will be more convenience if you start, restart, and stop the service using this tool rather than type the command, so you may want to clone it to desktop, nevertheless, this tool has some limitation, it isn’t able to Install and Remove/Uninstall the services.
0 comments:
Post a Comment