Help with mysqldump...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mangina

    Help with mysqldump...

    Hello all.
    Can anyone see why this snippet of code isnt dumping the databases using
    mysqldump ?
    All the credentials are correct (changed for the purpose of this post).

    $host = "localhost" ;
    $user = "root";
    $pass = "password";
    $database = "database";
    $dbname = array ("1","2","3","4 ","5");
    $savepath = "c:/inetpub/sqlbackup";
    $date = date("mdy-hia");

    $link = mysql_connect($ host, $user, $pass) or die("Could not connect");
    mysql_select_db ($database) or die("Could not select database");

    for ($i=0;$i<sizeof ($dbname);$i++)
    {
    $filename = "$savepath/$dbname[$i]-$date.sql";
    passthru("c:/mysql/bin/mysqldump --opt -h$host -u$user -p$pass $dbname[$i][color=blue]
    >$filename");[/color]
    }

    mysql_free_resu lt($result);
    mysql_close($li nk);


  • Dan Tripp

    #2
    Re: Help with mysqldump...

    Mangina wrote:
    [color=blue]
    > Hello all.
    > Can anyone see why this snippet of code isnt dumping the databases using
    > mysqldump ?
    > All the credentials are correct (changed for the purpose of this post).
    >
    > $host = "localhost" ;
    > $user = "root";
    > $pass = "password";
    > $database = "database";
    > $dbname = array ("1","2","3","4 ","5");
    > $savepath = "c:/inetpub/sqlbackup";
    > $date = date("mdy-hia");
    >
    > $link = mysql_connect($ host, $user, $pass) or die("Could not connect");
    > mysql_select_db ($database) or die("Could not select database");
    >
    > for ($i=0;$i<sizeof ($dbname);$i++)
    > {
    > $filename = "$savepath/$dbname[$i]-$date.sql";
    > passthru("c:/mysql/bin/mysqldump --opt -h$host -u$user -p$pass $dbname[$i]
    >[color=green]
    >>$filename") ;[/color]
    >
    > }
    >
    > mysql_free_resu lt($result);
    > mysql_close($li nk);
    >
    >[/color]

    I don't understand why "--opt" is in there.

    Regards,

    - Dan

    Comment

    • Mike Vore

      #3
      Re: Help with mysqldump...

      Checkyour mysql configuration (.my.cfg on unix). If you have
      parameters set in [client] and not in [mysqldump] they take
      precedience and you have problems. [client] seems to be a default set
      of settings.

      On Sun, 8 Feb 2004 20:03:21 -0900, Mangina <support@micros oft.com> wrote:[color=blue]
      >
      >
      > Hello all.
      > Can anyone see why this snippet of code isnt dumping the databases using
      > mysqldump ?
      > All the credentials are correct (changed for the purpose of this post).
      >
      > $host = "localhost" ;
      > $user = "root";
      > $pass = "password";
      > $database = "database";
      > $dbname = array ("1","2","3","4 ","5");
      > $savepath = "c:/inetpub/sqlbackup";
      > $date = date("mdy-hia");
      >
      > $link = mysql_connect($ host, $user, $pass) or die("Could not connect");
      > mysql_select_db ($database) or die("Could not select database");
      >
      > for ($i=0;$i<sizeof ($dbname);$i++)
      > {
      > $filename = "$savepath/$dbname[$i]-$date.sql";
      > passthru("c:/mysql/bin/mysqldump --opt -h$host -u$user -p$pass $dbname[$i][color=green]
      >>$filename") ;[/color]
      > }
      >
      > mysql_free_resu lt($result);
      > mysql_close($li nk);
      >
      >[/color]


      --
      Michael Vore, W3CCV M-ASA [Ka8]; WHIRL, ABC; CAW, CW, AAW
      http://mike.vorefamily.net/ohmywoodness <-You'll find items of interest here

      Comment

      • Dan Tripp

        #4
        Re: Help with mysqldump...

        Mangina wrote:
        [color=blue]
        > Hello all.
        > Can anyone see why this snippet of code isnt dumping the databases using
        > mysqldump ?
        > All the credentials are correct (changed for the purpose of this post).[/color]

        I think I found a couple of things. See below. =)

        [color=blue]
        > $host = "localhost" ;
        > $user = "root";
        > $pass = "password";
        > $database = "database";
        > $dbname = array ("1","2","3","4 ","5");
        > $savepath = "c:/inetpub/sqlbackup";
        > $date = date("mdy-hia");
        >
        > $link = mysql_connect($ host, $user, $pass) or die("Could not connect");
        > mysql_select_db ($database) or die("Could not select database");[/color]

        Above, you're specifying the database names... so unless you're running
        a query to get the db names, the two lines above aren't necessary. If
        you want to dump all the databases, it'd be easier to use the
        "--all-databases" flag with mysqldump than it would be to ask the db for
        all the names first.

        [color=blue]
        > for ($i=0;$i<sizeof ($dbname);$i++)
        > {
        > $filename = "$savepath/$dbname[$i]-$date.sql";
        > passthru("c:/mysql/bin/mysqldump --opt -h$host -u$user -p$pass $dbname[$i]
        >[color=green]
        >>$filename") ;[/color]
        >
        > }
        >
        > mysql_free_resu lt($result);
        > mysql_close($li nk);[/color]

        Same basic comment as above. Those two lines probably aren't necessary.

        I'm assuming that you're on a windows machine with IIS. =) Why else
        would one have a "C:" in their path name... and want to put stuff in
        "inetpub?. ;)

        Your mileage may vary... but the following worked for me. Please note
        that this *won't work* if safe mode is on in your php.ini file. Also,
        my machine (Apache/XP) choked on the forward slashes in the path to
        mysqldump, so I put in escaped backslashes. T'would be a different path
        on *nix.

        <?php

        $host = "localhost" ;
        $user = "user";
        $pass = "password";
        $dbnames = array ("db1","db2" );
        $savepath = "c:/inetpub/sqlbackup";
        $date = date("mdy-hia");

        foreach($dbname s as $dbname)
        {
        $filename = $savepath.$dbna me."-".$date.".s ql";
        $execCmd = "c:\\mysql\\bin \\mysqldump.exe -h$host -u$user -p$pass
        $dbname >> $filename";
        exec($execCmd);
        }

        ?>

        Regards,

        - Dan

        Comment

        • News

          #5
          Re: Help with mysqldump...

          "Dan Tripp" <thisIsNot@MyEM ailAddress.com> wrote in message
          news:a%MVb.2294 8$c81.9253@news svr25.news.prod igy.com...[color=blue]
          >
          > <?php
          >
          > $host = "localhost" ;
          > $user = "user";
          > $pass = "password";
          > $dbnames = array ("db1","db2" );
          > $savepath = "c:/inetpub/sqlbackup";
          > $date = date("mdy-hia");
          >
          > foreach($dbname s as $dbname)
          > {
          > $filename = $savepath.$dbna me."-".$date.".s ql";
          > $execCmd = "c:\\mysql\\bin \\mysqldump.exe -h$host -u$user -p$pass
          > $dbname >> $filename";
          > exec($execCmd);
          > }
          >
          > ?>[/color]

          Thank you very much for your help. I will try this out later tonight and
          post back.


          Comment

          Working...