Wednesday, September 24, 2008

Starting MySQL in NetBeans as root/administrator

As you may or may not know, NetBeans 6.1 and 6.5 provide the ability to let you start and stop your MySQL server directly from NetBeans. To be honest I wasn't sure how valuable this feature would be when I implemented it, but in my own work I've found it to be very nice. It's a small thing but it helps me maintain my "flow" when working with the database.

One challenge is that often MySQL can only be run with administrative/root privileges.

On Linux and Solaris you can use 'gksu' to start a program as root, and a dialog will appear asking you for the root password. So if you right-click on the MySQL node and choose Properties and then select the Admin tab, you can make gksu the command name and the actual command to start and stop MySQL is part of the command arguments. Here is a screen shot to give you the idea:

linux-properties.jpg

Now, gksu doesn't exist on Mac. The command to bring up a dialog for the administrator password is somewhat complex. So I've written a little script called "macsu" that looks like this:
#!/bin/sh/usr/bin/osascript -e "do shell script \"$@\" with administrator privileges"
Then in your Properties window you can do the following:

mac-properties.jpg

Et, voila, you get a prompt when you run the start command:



Note that my 'macsu' command doesn't handle "--" options well, so if you want to do "--console" you might have to wrap your mysql start command in your own script file, and then invoke that file from macsu.

To be honest I have no idea what you can do on Windows. Does anyone have any tips?

2 comments:

Unknown said...

It works if the macsu script is correctly wrapped, like

#!/bin/sh
/usr/bin/osascript -e "do shell script \"$@\" with administrator privileges"

Unknown said...

Thanks David. It works but the script must be correctly wrapped, like

#!/bin/sh
/usr/bin/osascript -e "do shell script \"$@\" with administrator privileges"