I use my PC for a lot of different things, and I don't necessarily need to have MySQL server running all the time, especially when I want to play a game. So I wondered if there was a simple way in which I could start and stop the server using a simple .bat file.
I had a look at the MySQL website and found a page that details how to start MySQL from the command line. This page suggested that I use the following command.
"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld"
Use the following command to stop the server. In this case the username is root and the password is wibble.
"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqladmin" -u root -pwibble shutdown
However, this just didn't work when I tried to use it in a .bat file. Realising that MySQL installs a service, I wondered if I could use the net command in order to start and stop the server. It turns out that the command is quite easy to use, so to turn the MySQL server on use the following command.
net start mysql
To stop the server use the following command.
net stop mysql
Add these commands to separate files, perhaps called stopmysql.bat and startmysql.bat, and you will have a neat way of turning on and off your MySQL server at the touch of a button.
If you are using Vista you can still do the same thing but you will need to right click and select "Run as administrator" or the script won't have enough privileges to alter the service.