james111 has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, I want to start and stop, remote mysql database through perl. But the thing is I need to log in as superuser to the remote machine and I am not sure how to login as a superuser to remote machine. Does any body knows how to do these things or can anybody tell me some example scripts?
  • Comment on Starting and stopping remote mysql database through perl

Replies are listed 'Best First'.
Re: Starting and stopping remote mysql database through perl
by davorg (Chancellor) on Jul 21, 2006 at 10:01 UTC

    You really don't want to be logging on as root on a remote machine. It's a far better idea to log on as your own user, but to allow that user to use "sudo" to restart the mysql server. Assuming that you have ssh running and an ssh key, then restarting the server could be as simple as:

    ssh user@remote_server sudo /sbin/service mysqld restart

    (I've assumed that you're using "service" to control mysql - you can change that to whatever command you need)

    In general using "sudo" gives you far greater control over who can use particular commands on your server.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Taking that further, ssh keys can be restricted to be used to execute just one command, which would be the one davorg suggested. Just another suggestion for the sake of security..

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Starting and stopping remote mysql database through perl
by CountZero (Bishop) on Jul 21, 2006 at 12:19 UTC
    I know it doesn't answer your question how to do this in Perl, but can't you use the MySQL Administrator program to access and manage the MySQL-server? It's the way I manage all my MySQL-servers.

    If the only Perl involved is "wrapping" a Perl-script around a system call, it seems hardly worth the trouble. Still, if that is what you want, have a look at the MySQL Instance Manager which you can access from a remote site.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Starting and stopping remote mysql database through perl
by lorn (Monk) on Jul 21, 2006 at 13:52 UTC

    Hi,
    you can use mysqladmin, passing argument -h, like this mysqladmin -h 192.168.1.10 -u root -p123 shutdown, read man mysqladmin, he have a lots of features.

    Lorn
    -http://lornlab.org
    -<a href="http://www.slackwarezine.com.br>http://www.slackwarezine.com.br-