2

I am working on backup and recovery of mySQL database using mysqldump. My code generates an sql file but its empty. Here's my complete code. Thanks a lot.

<?
   shell_exec("mysqldump -u root -p ilamdb > db/ilamdb.sql");
   echo "Back up complete.";
?>
user2004096
  • 27
  • 1
  • 2
  • 7
  • There is probably an error. You've already redirected the stdout to a file; try redirecting the stderr to another file (`2>anotherfile`) so you can capture the error message and look at it afterwards. – Celada Mar 08 '13 at 12:19
  • I've tried placing the file outside the folder but it has the same result. The page will display the string, file on the folder but still empty. – user2004096 Mar 08 '13 at 12:25
  • OK, but that has nothing to do with what I suggested... – Celada Mar 08 '13 at 12:26
  • Can you explain much further what you've suggested? – user2004096 Mar 08 '13 at 12:29
  • You are already capturing the stdout of the command into a file (with `> db/ilamdb.sql`). I suggest that you *also* capture the stderr (with `2>anotherfile`) so that you will be able to see the error message that the `mysqldump` command produces. – Celada Mar 08 '13 at 12:31

2 Answers2

3

You used the option -p which tells mysqldump to ask you for a password – which of course only works in an interactive shell. You will have to specify your password directly:

shell_exec("mysqldump -u root --password=yourpassword ilamdb > db/ilamdb.sql");

If you don't use a password, simply leave out this parameter:

shell_exec("mysqldump -u root ilamdb > db/ilamdb.sql");
0

MySQL backup syntax should be as below

mysqldump -u --password= >File.dmp

Buzz LIghtyear
  • 480
  • 5
  • 16