user2004096
user2004096

Reputation: 25

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";
  ?>

Upvotes: 1

Views: 286

Answers (1)

peterm
peterm

Reputation: 92845

  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);

Upvotes: 1

Related Questions