Django Anonymous
Django Anonymous

Reputation: 3025

mysqldump using php for database backup is not working

I have written this piece of code to take my database backup. I am using MySQL as my DB and PHP as a compiler.

<?php
$dbhost   = "localhost";
$dbuser   = "root";
$dbpwd    = "admin";
$dbname   = "mydatabase";
mysql_connect($dbhost, $dbuser, $dbpwd, $dbname) or die('Problem');
$dumpfile = $dbname . "_" . date("Y-m-d_H-i-s") . ".sql";
passthru("/usr/bin/mysqldump --opt --host=$dbhost --user=$dbuser --password=$dbpwd --all-databases > $dumpfile");
echo "$dumpfile "; passthru("tail -1 $dumpfile");
?>

The code get executed but the problem is the downloaded file is of 0KB i.e there is no data in the file.

What is the issue. I have searched a lot on internet but unable to find solution for myself.

Upvotes: 0

Views: 800

Answers (2)

Pret
Pret

Reputation: 21

If you are using Windows, place the mysqldump.exe executable in the same location as your backup script. That should work

Upvotes: 2

metalfight - user868766
metalfight - user868766

Reputation: 2750

Check permission for the directory in which your code is running. It should have write permission.

Upvotes: 0

Related Questions