Page 1 of 1

command line execution of mysqldump thru PHP

Posted: Sat Feb 08, 2003 11:27 am
by psmshankar
when i run the following in the browser, the progress bar keeps on moving but nothing is coming...

Code: Select all

<?php
$Path="C:\phpdev3\mysql3.23\bin";
$MySQLServer="localhost";
$MySQLUser="";
$MySQLPassword="";
$DBName="test";
$StorePath="C:\mysqlbackup\20030208"

$Command=$Path. "". "mysqldump -h".$MySQLServer." -u".$MySQLUser." -p".$MySQLPassword." --add-drop-table ".$DBName." > ".$StorePath. "" .$DBName.".sql";

passthru($Command,$result);
if ($result)
{
     echo "<br>Error! Database $DBName Not Backed Up";
}
else
{
     echo "Backup Successfull";
}
?>

when i comment the passthru statement then ok... i gave an echo statement to print the variable 'Command'

it printed the following:

c:\phpdev3\mysql3.23\bin\mysqldump -hlocalhost -u -p --add-drop-table test > c:\mysqlbackup\20030208\test.sql

i also tried with 'system' command...but nothing works..

when i typed the same thing in command prompt it works fine...
is there any thing i am missing out...

i am using win98/apache/mysql3.23/php 4

Posted: Sun Feb 09, 2003 8:39 pm
by volka
it is obvious from the output (and the script, too) that $MySQLUser and $MySQLPassword are blank.
Therefor the commandline tool will prompt for user/password and so the process waits (and since there is no further input it waits forever or 'til it's terminated [timeout of php] )

Posted: Sun Feb 09, 2003 8:44 pm
by psmshankar
means i cannot use empty password and username while using mysqldump.... is it?????

Posted: Sun Feb 09, 2003 8:47 pm
by volka
passing -u and/or -p means "hey mysqldump, here I give you user and password to use." Try without -u and -p

Why do you use --add-drop-table if you do not create tables?

Posted: Sun Feb 09, 2003 8:59 pm
by psmshankar
no still the same.... it goes on ..on ...

Posted: Sun Feb 09, 2003 9:01 pm
by volka
if you copy and paste the echo-output directly to a commandline and execute it what happens?

Posted: Sun Feb 09, 2003 9:03 pm
by psmshankar
there it is working fine...

Posted: Sun Feb 09, 2003 9:12 pm
by volka
I use (short version ;) )

Code: Select all

$user = 'volka';
$pass = '***';
$command = 'c:\\programme\\mysql\\bin\\mysqldump -hlocalhost -u '.$user.' -p'.$pass.' -c -r e:\\pm.sql -B phantasmorgia';
system($command, $retval);
to backup a database without problems.

Posted: Sun Feb 09, 2003 9:23 pm
by psmshankar
whats that -r stands for???
is that command u specified is used dump in one single file alone? or multiple files ".sql" files will be created for each database?

Posted: Sun Feb 09, 2003 9:33 pm
by psmshankar
whats that "phantasmorgia" in ur statement...
quite surprised that u didn't use any smileys in the first few posts...but later you did... :lol:

Posted: Sun Feb 09, 2003 9:55 pm
by volka
the command is used to dump the complete database phantasmorgia (only an example) to the file e:\pm.sql
mysqldump --help will show you a brief description of all available options.

Usually more smiles mean I had to think more about a text to write (and found nothing that can stand for its own without smiley)

Posted: Sun Feb 09, 2003 10:51 pm
by psmshankar
when i executed ur command(with appropriate changes) in the command prompt, it says there is no option like '-r'

so i removed that -r option and then run...
this is the command i typed (test is my database):

Code: Select all

c:\phpdev3\mysql3.23\bin\mysqldump -hlocalhost -c c:\mysqlbackup\test.sql -B test
it told me unknown database "c:\mysqlbackup\test.sql"

so i changed the command to the following:

Code: Select all

c:\phpdev3\mysql3.23\bin\mysqldump -hlocalhost -c -B test c:\mysqlbackup\test.sql
here it showed me the entier dump in the command prompt itself rather than creating the test.sql file...

so again i changed the command to

Code: Select all

c:\phpdev3\mysql3.23\bin\mysqldump -hlocalhost -c -B test &gt; c:\mysqlbackup\test.sql
this time it is ok and created the dump file...

but the same thing i run thru php

Code: Select all

<?php
$command = "c:\phpdev3\mysql3.23\bin\mysqldump -hlocalhost -c -B test > c:\mysqlbackup\test.sql";
system($command, $retval);
echo "<br>retval = $retval";
?>
just these 3 lines.... as usual it keeps on running...nothing i get...
i think when i use system command it just not working...
not only the mysqldump command,ubut also when i try to call a notepad.exe thru this command it doesn't work..
is there anything i am missing out...is there anything i need to do in ini file?? wondering..
v

Posted: Sun Feb 09, 2003 11:14 pm
by volka
a common pitfall is that programs that prompt something will hang system()/exec()/... and so will notepad.exe as it tries to create a gui that will not stop until it is manually closed.

Posted: Mon Feb 10, 2003 12:50 am
by psmshankar
ok if u say so...ok 5n..
i created a batch file with the name "MMLSDBBackup.bat"
it contains the following:

Code: Select all

REM ******************************************** 
REM ****************** BACKUP ****************** 
REM ******************************************** 

SET PATH="%PATH%";C:\phpdev3\mysql3.23\bin; 
mysqldump --opt test > c:\MMLSDump\Dump.sql 

REM ******************************************** 
REM **************** END BACKUP **************** 
REM ********************************************


and saved in "D:\Shankar" folder...

then in my program i called this to execute

Code: Select all

$command = "D:\\Shankar\\MMLSDBBackup.bat"; 
system($command, $retval); 
echo "<br>retval = $retval";
even then it hangs...didn't do anything...the icon keeps on moving in the browser...

so what do you think about this?

Posted: Mon Feb 10, 2003 1:10 am
by volka
I'm clueless but strongly suggest creating an account in mysql for mysqldump and use it

Code: Select all

mysqldump -u user -ppassword ...