Configure MySQL Services on Windows
Introduction
I am learning PHP recently so I wanted to install MAMP on my laptop. The installation was successful. However, when I started to run MAMP, it raised the warning “mysql needs open port 3306 …” because MAMP uses MySQL. This reminded me that I have already installed MySQL on my laptop and the service was always running. Since I do not want to delete MySQL, I need to find a way to get MAMP and MySQL to stay peacefully together. One way to solve the problem is to use another port, other than port 3306, for MAMP. But I don’t like it. I want to assign the port to MAMP or MySQL whenever I want to use either one. Running MySQL constantly from Windows startup does not make sense to me, since it is only a laptop for the local test but not a service host.
Solution
I did some Google searches and found the solutions. To manipulate the Windows services, one has to run commands as administrator in the terminal (Right click the terminal and run as administrator).
The MySQL service name might be different from “MySQL”. To find out the MySQL service name, run the following command to find MySQL services among all the services.
1 | sc query type= service |
My MySQL service name is “Thinkpad-Mysql” (I configured it and later I forgot). To stop the service, run the following command.
1 | net stop Thinkpad-Mysql |
However, it is still not enough. Next time you start the computer, the “Thinkpad-Mysql” service will automatically run since startup. To prevent his, run the following command.
1 | sc config Thinkpad-Mysql start= disabled |
To restart “Thinkpad-Mysql” service, basically reverse the command we have run.
1 | sc config Thinkpad-Mysql start= auto |
Notes
I also tried to set the “Thinkpad-Mysql” service “manual” by running the following command.
1 | sc config Thinkpad-Mysql start= manual |
However, I failed. But the following command seems to work for “manual” (Check Microsoft Documentation).
1 | sc config Thinkpad-Mysql start= demand |
If the service becomes “demand”, it could be turned on or off by running single commands.
1 | net start Thinkpad-Mysql |
or
1 | net stop Thinkpad-Mysql |
Configure MySQL Services on Windows
https://leimao.github.io/blog/Configure-MySQL-Services-Windows/