Setting up MySQL Proxy as a Service on Windows

In the newer versions of MySQL Proxy (0.7.2 and newer), it is now possible to create a Windows service for MySQL Proxy due to the inclusion of “mysql-proxy-svc.exe”.

Basically, you could use “mysql-proxy-svc.exe” in lieu of “mysql-proxy.exe” from the command line and you would not notice a difference. However, just invoking this will not create a service for MySQL Proxy. Furthermore, you cannot invoke it with the “–install” option as you can with mysqld.

But, you can create a service for MySQL Proxy using the “sc” command with “mysql-proxy-svc.exe”.

Say I want to create a service that starts automatically when my system is started/rebooted. I also want it to load a certain lua script, say capture-errors.lua. Given this, I would use the following command:

sc create "proxy" DisplayName= "MySQL Proxy" start= "auto"
binPath= "C:Program FilesMySQLmysql-proxy-0.7.2binmysql-proxy-svc.exe
--proxy-lua-script=capture-errors.lua"

Here is the session from my console:

C:Program FilesMySQLmysql-proxy-0.7.2bin>sc create "proxy"
DisplayName= "MySQL Proxy" start= "auto"
binPath= "C:Program FilesMySQLmysql-proxy-0.7.2binmysql-proxy-svc.exe
--proxy-lua-script=capture-errors.lua"
[SC] CreateService SUCCESS

Once you have this set-up, you can easily start-up or shutdown the proxy. For instance, the following two commands will start and stop the proxy, respectively:

net start proxy
net stop proxy

Now, a couple of notes about the “sc create” statement:

  1. This will create the service with the name of “proxy”.
  2. I used a “start” type of “auto”. This will mean it will start up automatically when you reboot your system. If you remove that option, it will default to “manual”.
  3. You need a space after each equal sign (=).
  4. I had to use double-quotes (“) around each parameter value, as well as the service name, otherwise it wouldn’t create the service properly on my machine.
  5. The lua script, capture-errors.lua, is located in the proxy basedir (C:Program FilesMySQLmysql-proxy-0.7.2) and so it can be read from that location without a full path. If you have this in a different location, you would need to specify the full path.

If for some reason you want to delete this service, you can issue the following command (where “proxy” is the name of the service that you gave it using the above command):

sc delete proxy

And for more details on “sc”, please refer to the following Microsoft KB article:

http://support.microsoft.com/kb/251192

Tags: , , ,

2 Responses to “Setting up MySQL Proxy as a Service on Windows”

  1. [...] Setting up MySQL Proxy as a Service on Windows « Chris on MySQL [...]

  2. [...] and instead of –defaults-file=, use –proxy-lua-script= (in fact, I actually had a post on this close to a year ago, but my example only had one path that contained a space, so the above syntax was not [...]


Period Panties by Period Panteez Menstrual Underwear Menstruation PMS Panty