命令在php中还原mysql db备份 [英] command restore mysql db backup in php

查看:113
本文介绍了命令在php中还原mysql db备份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还原db文件时出现问题.以下是我用来还原的脚本:

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

备份文件时没有发现问题.当我复制n并将备份内容手动粘贴到数据库中时,它可以完美还原而不会出现问题.但是,当我运行还原脚本以执行还原时,该文件会保持加载很长时间而不会提示任何错误.因此,我停止了加载,似乎没有任何表被还原到数据库中.

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.

当我尝试从cmd运行脚本时,还原可以完全而快速地完成.在这种情况下,我将备份文件与mysql.exe放在同一文件夹中

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

这是我在cmd中执行命令的方式:

This is how i do the command in the cmd:

C:\xampp\mysql\bin>mysql -u root -p  fhc_test < fhc.sql

有人可以帮助我弄清楚我的还原脚本中存在什么问题吗?我已经做了很多检查,似乎代码没有错误.我是否必须从c:/xampp/mysql/bin复制mysql.exe文件,并将其放入放置php文件的文件夹中?

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.

推荐答案

在PowerShell中运行命令,您将收到此错误:

Run the command in PowerShell and you will get this error:

The '<' operator is reserved for future use.

您显然是在Windows中运行此程序,因此需要将语法调整为此:

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

这篇关于命令在php中还原mysql db备份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆