简体   繁体   中英

mysqldump generates zero-length file

I am working with myqldump that generates a zero-length file. I tried it many times, but it seems that that it only outputs a zero-length file. I don't know why. Do I need to install something or what ?

  <?
    shell_exec("mysqldump -hlocalhost  -uroot -p  -A> db/ilamdb.sql ");
    echo "complete";
  ?>
  1. Provide a full path to mysqldump
  2. Provide a password for a user (root in your case). Leaving -p means ask user for password interactively. Escape or put the password in quotes if it contains one of the following characters * ? [ < > & ; ! | $ * ? [ < > & ; ! | $
  3. For the good measure use --no-defaults option. You might not need this in your case.
  4. And finally redirect stderr to stdout adding 2>&1 at the end of the command. That way you'll get the error message for debugging purposes in your file instead of just empty file if an error occurs.

Therefore your code to invoke mysqldump might look like this

$pwd = '*******';
$cmd = "/usr/local/mysql/bin/mysqldump -hlocalhost -uroot -p'$pwd' -A> db/ilamdb.sql 2>&1";
shell_exec($cmd);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM