问题
i'm having a problem when restoring the db file. Below is that script that I use to restore:
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpwd = "";
$dbname = "fhc_test";
$dumpfile = "backup/".$_GET['id'].".sql";
exec("C://xampp/mysql/bin/mysql -u $dbuser -p $dbpwd $dbname < $dumpfile");
?>
Below is the script that I use to do the backup:
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpwd = "";
$dbname = "fhc";
date_default_timezone_set("Asia/Singapore");
$dumpfile = "backup/". $dbname . "_" . date("d-m-Y_H_i_s") . ".sql";
exec("C://xampp/mysql/bin/mysqldump --opt --host=$dbhost --user=$dbuser --password=$dbpwd $dbname > $dumpfile");
?>
There is no problem found when backup-ing the file. When i copy n paste the backup content into the database manually, it can restore perfectly without problem. But when i'm running the restore script to perform the restore, the file keeps loading for so long without prompting any error. So, I stop the loading, and it seems like there is no tables been restored into the database.
When i try to run the script from the cmd, the restore can be done completely and fast. In this case, I put the backup file in the same folder as the mysql.exe
This is how i do the command in the cmd:
C:\xampp\mysql\bin>mysql -u root -p fhc_test < fhc.sql
can anyone help me figure out what is the problem that i have in my restore script? bcos i have done so many checking and it seems like there is no error with the code. Do i have to copy the mysql.exe file from c:/xampp/mysql/bin and put it into the same folder where i put my php file?
I really dunno what I have to do with this.
回答1:
Given that you use:
C:\xampp\mysql\bin>mysql -u root -p fhc_test < fhc.sql
it is the user root you are trying with. Not phpmyadmin user. So you need to use the -p
option to give the password for root.
回答2:
Run the command in PowerShell and you will get this error:
The '<' operator is reserved for future use.
You are obviously running this in Windows so you need to adjust your syntax to this:
Get-Content fhc.sql | mysql -u root -p fhc_test
来源:https://stackoverflow.com/questions/19331490/command-restore-mysql-db-backup-in-php