问题
i can't seem to restore my database backup in php. this is my code
<?php
$host = 'localhost';
$user = 'root';
$pass = ' ';
$dbname = 'itravel';
date_default_timezone_set('Asia/Kuala_Lumpur');
$date = date('Y_m_d');
if(isset($_POST['backup']))
{
$backup = "c:/xampp/mysql/bin/mysqldump --opt -h $host -u $user $dbname > itravel_backup_$date.sql";
system($backup);
}
if(isset($_POST['restore']))
{
$restore = "c:/xampp/mysql/bin/mysqldump --opt -h $host -u $user $dbname < itravel_backup_$date.sql";
system($restore);
}
?>
backup was successful but the restore is a failure. help me guys!
updated the code with
<?php
$host = 'localhost';
$user = 'root';
$pass = ' ';
$dbname = 'itravel';
//date_default_timezone_set('Asia/Kuala_Lumpur');
//$date = date('Y_m_d');
$backup_name = 'itravel_backup.sql';
if(isset($_POST['backup']))
{
$backup = "c:/xampp/mysql/bin/mysqldump --opt -h $host -u $user $dbname > $backup_name";
system($backup);
}
if(isset($_POST['restore']))
{
//$restore = "c:/xampp/mysql/bin/mysqldump --opt -h $host -u $user $dbname < itravel_backup_$date.sql";
//system($restore);
$restore = "c:/xampp/mysql/bin/mysql --opt -h $host -u $user $dbname < $backup_name";
system($restore);
}
?>
but still not working
回答1:
You need to use the mysql
binary to restore, not mysqldump
.
来源:https://stackoverflow.com/questions/14799987/restore-backup-mysqldump-php