Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with mysqldump...

Mangina
Guest
 
Posts: n/a
#1: Jul 17 '05
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_result($result);
mysql_close($link);



Dan Tripp
Guest
 
Posts: n/a
#2: Jul 17 '05

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_result($result);
> mysql_close($link);
>
>[/color]

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

Regards,

- Dan
http://blog.dantripp.com/
Mike Vore
Guest
 
Posts: n/a
#3: Jul 17 '05

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@microsoft.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_result($result);
> mysql_close($link);
>
>[/color]


--
Michael Vore, W3CCV M-ASA [Ka8]; WHIRL, ABC; CAW, CW, AAW
http://mike.vorefamily.net/ohmywoodness <-You'll find items of interest here
Dan Tripp
Guest
 
Posts: n/a
#4: Jul 17 '05

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_result($result);
> mysql_close($link);[/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($dbnames as $dbname)
{
$filename = $savepath.$dbname."-".$date.".sql";
$execCmd = "c:\\mysql\\bin\\mysqldump.exe -h$host -u$user -p$pass
$dbname >> $filename";
exec($execCmd);
}

?>

Regards,

- Dan
http://blog.dantripp.com/
News
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Help with mysqldump...


"Dan Tripp" <thisIsNot@MyEMailAddress.com> wrote in message
news:a%MVb.22948$c81.9253@newssvr25.news.prodigy.c om...[color=blue]
>
> <?php
>
> $host = "localhost";
> $user = "user";
> $pass = "password";
> $dbnames = array ("db1","db2");
> $savepath = "c:/inetpub/sqlbackup";
> $date = date("mdy-hia");
>
> foreach($dbnames as $dbname)
> {
> $filename = $savepath.$dbname."-".$date.".sql";
> $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.


Closed Thread