is there any way to start mySQL (ie. run usr/local/mysql/bin/mysqld) using PHP? If so...what is it?

Thanks a bunch,
Raif.

    Hi,
    If you've given the user "nobody" access to your mysqld file you can use the backtick operator to run a command, but the user your web server runs under (Generally "Nobody") must have execute access to the file.

    Example:
    $result = /usr/local/bin/apachectl restart;
    (Those are not single quotes, they are backticks, it's next to the one key... with the tilda)

    Tim
    http://www.tier1host.net

    Raif wrote:

    is there any way to start mySQL (ie. run usr/local/mysql/bin/mysqld) using PHP? If so...what is it?

    Thanks a bunch,
    Raif.

      That doesn't seem to work. I went to the manual and looked at a few different things that are similar to the backtick.

      The code of my file looks like this:

      <?
      function reconnect() {
      /* //backtick: did not work
      $result = /usr/local/mysql/bin/mysqld &;
      echo "$result";

      //system(): did not work
      $result = system("/usr/local/mysql/bin/mysqld &",$result);
      echo "$result";
      */
      //passthru(): Works without the &. however, without the &, nothing happens.
      passthru("/usr/local/mysql/bin/mysqld &",$result);
      echo "$result";

      echo "\n<b>Could not connect to the database.</b>";

      if ($result) {
      echo "\n<BR><i>Refresh and try again.</i>";
      } else {
      echo "\n<BR><i>Failed to restart socket. Please contact the webmaster and notify them.</i>";
      }
      }

      $connection = @mysql_connect() or die(reconnect())

      ?>

      Is there something I'm doing wrong in one of the codes?

      Thank you for your quick reply,
      Raif.

        Does the user "nobody" have execute access to that file? That's the only thing I can think of. by all means, it should work.

          I CHMODed it to 777, would that give "nobody" access?

          Raif.

            i'd change the group to "nobody" leaving "root" as the owner, and give it a permissoin of 771... giving it perms of 777 allows any user on the web server to mess with your mysql... comands:
            chown root:nobody mysqld
            chmod 771 mysqld

              I tried doing the "chown root:nobody mysqld" command, but the server just returned "'CHOWN root: nobody mysqld': command not understood."

              Thank you for your help so far,
              Raif.

                it doesn't seem to be.

                I concidered that the problem might be that it isn't connected through FTP or such. however, that didn't work either. Additionally, it seems as if I don't have access to do a CHOWN command (I don't have the server with me, it's hosted).

                Is there any other way this could be done? Right now, the file is listed as being owned by tsinaior, which is my login username...

                I've been wondering, though, after I start the mysqld file, and begin mysql, how long does it run for? and how can I stop it from running?

                Thanks very much for all the help you've given me so far,
                Raif.

                  This should have nothing to with whether your connected via FTP or what... its the script which is running on that server, running a command from the servers command line. I've not asked this before, but what is the purpose of starting mysql again with this command in the script? are you trying to do something that could possibly be done in a different way?

                    Well, mysql, after a period of time, stops, and I have to re-run the mysqld file. what I'm wanting to do is to run the mysqld file automatically, so that, when it stops, it can be quickly restarted and people can access the databases again.

                    Of course, I could stop it every month, and restart it that way, but I don't know how to stop it (I'm pretty much new with mySQL, only starting using it about a month or two ago, and I've only been using small and simple tables)

                    Thank you very much for your help,
                    Raif.

                      Write a Reply...