恢复备份mysqldump php

时间:2013-02-10 16:42:13

标签: php mysql mysqldump

我似乎无法在php中恢复我的数据库备份。这是我的代码

<?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);
        }
        ?>

备份成功但恢复失败。帮帮我们!


使用

更新代码
<?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);
        }
        ?>

但仍无法正常工作

1 个答案:

答案 0 :(得分:1)

您需要使用mysql二进制文件进行还原,而不是mysqldump