1

I'm trying to restore MySQL dump created the following way:

$file = '/path/to/file.sql';
exec('mysqldump -u '.DB_USER.' -p'.DB_PASS.' '.DB_NAME.' > '.$file);

the above creates the dump as expected, then to restore I'm trying to use the following:

$file = '/path/to/file.sql';
exec('mysql -u '.DB_USER.' -p'.DB_PASS.' '.DB_NAME.' < '.$file);

but for some reason it doesn't do anything.

Please note that the constants contain the relevant database connection parameters.

Any idea what I'm doing wrong?

2
  • try the full path of mysql, like /usr/bin/mysql or whatever and add some error checking on the exec call. debug info? Commented May 6, 2011 at 18:22
  • Have you tested the string produced by PHP in a MySQL client connection to make sure it works? Commented May 6, 2011 at 18:25

2 Answers 2

1

use mysql -e 'source $file' instead of redirection

Sign up to request clarification or add additional context in comments.

Comments

0
$file = realpath('file.sql');
exec('mysqldump -u ' . DB_USER . ' -p' . DB_PASS . ' ' . DB_NAME . ' > ' . $file);

Perhaps try this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.