php exec() - mysqldump creates an empty file

后端 未结 7 1635
再見小時候
再見小時候 2021-01-11 14:22

I want to create a backup from a database, but I get only a blank file.

include(\'config.php\');

$command = \"mysqldump --opt -h \".$_host.\" -u \".$_user.\         


        
相关标签:
7条回答
  • 2021-01-11 14:58

    For those on Macs

    I was battling this issue the entire evening today. Silly mistake: one needs to chmod the directory that you are dumping the file to.

    I ran this which fixed the issue:

    chmod -R 777 your_dump_directory/
    
    0 讨论(0)
  • 2021-01-11 14:59

    Take the variables out of the quotes and remove --opt.

    Also make sure that you are having unique file names

    $backupfile = $dbname . date("Y-m-d-H-i-s") . '.sql';

    $command = "D:\xampp\mysql\bin\mysqldump -u $_user -p$_pass $_db > $backupfile";

    system($command);

    0 讨论(0)
  • 2021-01-11 15:01

    These are the parameters

    -uROOT -pPASSWORD --databases DB --result-file=FILE.SQL

    0 讨论(0)
  • 2021-01-11 15:05

    If you look at the manual for exec the output goes to an array that is the second argument. That may be the source of the problem.

    0 讨论(0)
  • 2021-01-11 15:06

    You should remove the space between the -p and the password.

    --opt isn't needed with recent versions of mysql.

    Other than that, your syntax is correct so if it doesn't work with the -p fix, you should check the parameters and the produced command.

    0 讨论(0)
  • 2021-01-11 15:11

    Try this one:

    $command = 'd:\xampp\mysql\bin\mysqldump --opt -u '.$_user.' -p'.$_pass.' '.$_db.' > test.sql 2>&1';
    

    -its about permission issue.

    0 讨论(0)
提交回复
热议问题