开发者

MySQL database restore using PHP

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?


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


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

Perhaps try this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜