Forum Moderators: coopster

Message Too Old, No Replies

mysqldump creates empty file

         

jackvull

10:01 am on Sep 1, 2005 (gmt 0)

10+ Year Member



Hi
I have the following code running on a Windows PC (it actually needs to work in a Linux environment on live but still developing it). It seems to create the a.sql file but there is nothing in the a.sql file even though there is data in the database. Any ideas?

<?php
include('session.php');

//---------------------
//Daily DB backup
//---------------------
$date = date("Ymd");

//DEV
$cmd1 = "/Program Files/MySQL/MySQL Server 4.1/bin/mysqldump --all-databases > /Inetpub/wwwroot/Test/Backups/a.sql";

//LIVE
//$cmd1 = "/usr/bin/mysqldump --add-drop-table --host=ahost.net --user=aaa --password=aaa --all-databases > /home4/aaa/sc11883-LGVN/Backups/a.sql";

passthru($cmd1);

echo "Done";

?>

jackvull

11:42 am on Sep 1, 2005 (gmt 0)

10+ Year Member



I figure this is because it is not actioning themysqldump command but that is the correct path.
I have tried accessing the mysqldump utility directly from the Windows cmd line and get the following:
\Program Files\MySql\MySql Server 4.1\bin/mysqldump > a.sql

'\Program' is not recognised as an internal or external command

ergophobe

1:04 pm on Sep 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Don't you need to specify a drive letter in windows?

C:/Program Files/

jackvull

1:31 pm on Sep 1, 2005 (gmt 0)

10+ Year Member



Tried that and same thing. If I could get the command to work from the command line then I'd use eactly the same path in the $cmd1 variable but it won't work from the Windows command line due to the error. If I go directly to the folder first and then issue a direct mysqldump command then it works fine:
e.g. C:/> cd Program Files/MySql/MySql Server 4.1/bin
C:/> mysqldump --all-databases > /InetPub/wwroot/Test/Backups/a.sql

jackvull

1:39 pm on Sep 1, 2005 (gmt 0)

10+ Year Member



Even stranger:
C:\winnt\system32\pconfig works from the command line but
C:\program files\mysql\mysql server 4.1\bin\mysqldump gives 'c:\program' is not recognised as an internal or external command

jackvull

1:44 pm on Sep 1, 2005 (gmt 0)

10+ Year Member



If I relocate the mysqldump.exe to a different folder then this works correctly from the script:
$cmd1 = "C:\PHP\test\mysqldump ....etc.

SO, it must be something to do with the space between Program and Files in the Program FIles folder. Is there a way to escape this?

bunkermaster

3:53 pm on Sep 1, 2005 (gmt 0)

10+ Year Member



use old DOS path maybe (8 characters)...

coopster

4:13 pm on Sep 1, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



When using WINDOWS I like to use str_replace to change the directory separator:

$dir = "C:/Program Files/MySQL/MySQL Server 4.1/bin/"; 
$dir = str_replace('/', DIRECTORY_SEPARATOR, $dir);
$cmd1 = '$dir' . "mysqldump --all-databases > /Inetpub/wwwroot/Test/Backups/a.sql";

ergophobe

9:35 pm on Sep 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




'c:\program'

Looks like it's having trouble with paths with spaces in them. That's part of why I don't put much of anything, and especially not servers, in the "Program Files" dir on windows. I like to have a programs partition so the path is more like

G:\mysql\mysql.exe

Tom