开发者

MySQL database restore using PHP

开发者 https://www.devze.com 2023-03-04 10:04 出处:网络
I\'m trying to restore MySQL dump created the following way: $file = \'/path/to/file.开发者_如何学运维sql\';

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

精彩评论

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

关注公众号