Starting And Stopping MySQL Using Windows .bat Files

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.

Comments

Deep appreciation for outlining this process!

Permalink
How would you write the .bat file so that you can make one button that toggles it on and off, instead of writing two separate buttons?
Permalink
may be you can search at google.
Permalink

net start "name of the sql service"

Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
7 + 11 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.