php備份和恢復(fù)數(shù)據(jù) php備份和恢復(fù)數(shù)據(jù)一樣嗎

php對(duì)mysql數(shù)據(jù)庫的備份及還原:

php對(duì)mysql數(shù)據(jù)庫的備份及還原:

成都創(chuàng)新互聯(lián)公司專注于企業(yè)成都全網(wǎng)營銷、網(wǎng)站重做改版、西雙版納網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5響應(yīng)式網(wǎng)站、商城網(wǎng)站定制開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為西雙版納等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

生成文件但是內(nèi)容為空,說明:php執(zhí)行沒問題,mysqldump也運(yùn)行,初步判斷問題出在mysqldump沒正常運(yùn)行。建議你到服務(wù)器上運(yùn)行 "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump -uroot -hlocalhost -p123 --opt -B rsgl ../bak/xxx.sql"

看能否正常生成sql文件

一年四季春常在 萬紫千紅永開花 喜迎新春

求thinkphp 數(shù)據(jù)庫的備份、還原的腳本

一、備份數(shù)據(jù)庫并下載到本地【db_backup.php】

代碼代碼如下:

?php

// 設(shè)置SQL文件保存文件名

$filename=date("Y-m-d_H-i-s")."-".$cfg_dbname.".sql";

// 所保存的文件名

header("Content-disposition:filename=".$filename);

header("Content-type:application/octetstream");

header("Pragma:no-cache");

header("Expires:0");

// 獲取當(dāng)前頁面文件路徑,SQL文件就導(dǎo)出到此文件夾內(nèi)

$tmpFile = (dirname(__FILE__))."\\".$filename;

// 用MySQLDump命令導(dǎo)出數(shù)據(jù)庫

exec("mysqldump -u$cfg_dbuser -p$cfg_dbpwd --default-character-set=utf8 $cfg_dbname ".$tmpFile);

$file = fopen($tmpFile, "r"); // 打開文件

echo fread($file,filesize($tmpFile));

fclose($file);

exit;

?

二、還原數(shù)據(jù)庫【db_restore.php】

代碼代碼如下:

form id="form1" name="form1" method="post" action=""

【數(shù)據(jù)庫SQL文件】:input id="sqlFile" name="sqlFile" type="file" /

input id="submit" name="submit" type="submit" value="還原" /

/form

?php

// 我的數(shù)據(jù)庫信息都存放到config.php文件中,所以加載此文件,如果你的不是存放到該文件中,注釋此行即可;

require_once((dirname(__FILE__).'/../../include/config.php'));

if ( isset ( $_POST['sqlFile'] ) )

{

$file_name = $_POST['sqlFile']; //要導(dǎo)入的SQL文件名

$dbhost = $cfg_dbhost; //數(shù)據(jù)庫主機(jī)名

$dbuser = $cfg_dbuser; //數(shù)據(jù)庫用戶名

$dbpass = $cfg_dbpwd; //數(shù)據(jù)庫密碼

$dbname = $cfg_dbname; //數(shù)據(jù)庫名

set_time_limit(0); //設(shè)置超時(shí)時(shí)間為0,表示一直執(zhí)行。當(dāng)php在safe mode模式下無效,此時(shí)可能會(huì)導(dǎo)致導(dǎo)入超時(shí),此時(shí)需要分段導(dǎo)入

$fp = @fopen($file_name, "r") or die("不能打開SQL文件 $file_name");//打開文件

mysql_connect($dbhost, $dbuser, $dbpass) or die("不能連接數(shù)據(jù)庫 $dbhost");//連接數(shù)據(jù)庫

mysql_select_db($dbname) or die ("不能打開數(shù)據(jù)庫 $dbname");//打開數(shù)據(jù)庫

echo "p正在清空數(shù)據(jù)庫,請(qǐng)稍等....br";

$result = mysql_query("SHOW tables");

while ($currow=mysql_fetch_array($result))

{

mysql_query("drop TABLE IF EXISTS $currow[0]");

echo "清空數(shù)據(jù)表【".$currow[0]."】成功!br";

}

echo "br恭喜你清理MYSQL成功br";

echo "正在執(zhí)行導(dǎo)入數(shù)據(jù)庫操作br";

// 導(dǎo)入數(shù)據(jù)庫的MySQL命令

exec("mysql -u$cfg_dbuser -p$cfg_dbpwd $cfg_dbname ".$file_name);

echo "br導(dǎo)入完成!";

mysql_close();

}

?

php,mysql數(shù)據(jù)庫備份和還原的最理想方式,類似phpadmin的代碼

一、備份數(shù)據(jù)庫并下載到本地【db_backup.php】

復(fù)制代碼 代碼如下:

?php

// 設(shè)置SQL文件保存文件名

$filename=date("Y-m-d_H-i-s")."-".$cfg_dbname.".sql";

// 所保存的文件名

header("Content-disposition:filename=".$filename);

header("Content-type:application/octetstream");

header("Pragma:no-cache");

header("Expires:0");

// 獲取當(dāng)前頁面文件路徑,SQL文件就導(dǎo)出到此文件夾內(nèi)

$tmpFile = (dirname(__FILE__))."\\".$filename;

// 用MySQLDump命令導(dǎo)出數(shù)據(jù)庫

exec("mysqldump -u$cfg_dbuser -p$cfg_dbpwd --default-character-set=utf8 $cfg_dbname ".$tmpFile);

$file = fopen($tmpFile, "r"); // 打開文件

echo fread($file,filesize($tmpFile));

fclose($file);

exit;

?

二、還原數(shù)據(jù)庫【db_restore.php】

復(fù)制代碼 代碼如下:

form id="form1" name="form1" method="post" action=""

【數(shù)據(jù)庫SQL文件】:input id="sqlFile" name="sqlFile" type="file" /

input id="submit" name="submit" type="submit" value="還原" /

/form

?php

// 我的數(shù)據(jù)庫信息都存放到config.php文件中,所以加載此文件,如果你的不是存放到該文件中,注釋此行即可;

require_once((dirname(__FILE__).'/../../include/config.php'));

if ( isset ( $_POST['sqlFile'] ) )

{

$file_name = $_POST['sqlFile']; //要導(dǎo)入的SQL文件名

$dbhost = $cfg_dbhost; //數(shù)據(jù)庫主機(jī)名

$dbuser = $cfg_dbuser; //數(shù)據(jù)庫用戶名

$dbpass = $cfg_dbpwd; //數(shù)據(jù)庫密碼

$dbname = $cfg_dbname; //數(shù)據(jù)庫名

set_time_limit(0); //設(shè)置超時(shí)時(shí)間為0,表示一直執(zhí)行。當(dāng)php在safe mode模式下無效,此時(shí)可能會(huì)導(dǎo)致導(dǎo)入超時(shí),此時(shí)需要分段導(dǎo)入

$fp = @fopen($file_name, "r") or die("不能打開SQL文件 $file_name");//打開文件

mysql_connect($dbhost, $dbuser, $dbpass) or die("不能連接數(shù)據(jù)庫 $dbhost");//連接數(shù)據(jù)庫

mysql_select_db($dbname) or die ("不能打開數(shù)據(jù)庫 $dbname");//打開數(shù)據(jù)庫

echo "p正在清空數(shù)據(jù)庫,請(qǐng)稍等....br";

$result = mysql_query("SHOW tables");

while ($currow=mysql_fetch_array($result))

{

mysql_query("drop TABLE IF EXISTS $currow[0]");

echo "清空數(shù)據(jù)表【".$currow[0]."】成功!br";

}

echo "br恭喜你清理MYSQL成功br";

echo "正在執(zhí)行導(dǎo)入數(shù)據(jù)庫操作br";

// 導(dǎo)入數(shù)據(jù)庫的MySQL命令

exec("mysql -u$cfg_dbuser -p$cfg_dbpwd $cfg_dbname ".$file_name);

echo "br導(dǎo)入完成!";

mysql_close();

}

?

php+mysql如何在后臺(tái)備份恢復(fù)數(shù)據(jù)庫,我是新手

1,恢復(fù)前備份。2,有之前的備份才可以恢復(fù)。3,下載數(shù)據(jù)庫管理工具,sqlyun,navcat,等可進(jìn)行導(dǎo)入導(dǎo)出。4.注意恢復(fù)期間對(duì)前臺(tái)影響。(最好關(guān)閉前臺(tái)訪問)5.做好出問題時(shí)的應(yīng)對(duì)準(zhǔn)備

php備份恢復(fù)MYSQL數(shù)據(jù)庫

// Create SQL file header:$sqlbackup .= "# MySQL backup of " . $dname . ":\n";$sqlbackup .= "# Generated on " . date('Y-m-d') . " at " . date("H:i:s") . ".\n\n";

// Get the tables to backup:$tables = mysql_list_tables($dname);for($i = 0; $i mysql_num_rows($tables); $i++) {

$table = mysql_tablename ($tables, $i);$sqlbackup .= "# Data for $table: \n";

$tabledata = mysql_query("SELECT * FROM $table");$num_fields = mysql_num_fields($tabledata);$numrow = mysql_num_rows($tabledata);while( $row = mysql_fetch_array($tabledata, MYSQL_NUM)) {

// Add commands so backup can be used by SQL:$sqlbackup .= "INSERT INTO ".$table." VALUES(";for($j = 0; $j $num_fields; $j++) {$row[$j] = addslashes($row[$j]);$row[$j] = str_replace("\n","\\n",$row[$j]);$row[$j] = str_replace("\r","",$row[$j]);if (isset($row[$j]))$sqlbackup .= "\"$row[$j]\"";else$sqlbackup .= "\"\"";if ($j($num_fields-1))$sqlbackup .= ", "; }$sqlbackup .= ");\n"; }if ($i + 1 != mysql_num_rows($tables))$sqlbackup .= "\n"; }

// Find out how long the file is for the browser:$howlong = strlen($sqlbackup);

// Construct file name:$sqlfname = "db_" . $dname . date("_m_d_Y");

header("Content-type: text/sql");header("Content-Length: $howlong");header("Content-Disposition: attachment; filename=$sqlfname.sql");echo $sqlbackup;

PHP+MYSQL的數(shù)據(jù)庫如何備份和還原?

有很多軟件可以使用,比如phpmyadmin,sqlyog等等

下載一個(gè)phpmyadmin并且配置好(網(wǎng)上有如何配置),其中就有備份還原數(shù)據(jù)庫的圖標(biāo),很簡單

補(bǔ)充:----------------------

對(duì)啊,點(diǎn)導(dǎo)出,然后執(zhí)行就可以了啊

分享題目:php備份和恢復(fù)數(shù)據(jù) php備份和恢復(fù)數(shù)據(jù)一樣嗎
轉(zhuǎn)載來源:http://muchs.cn/article10/hgepdo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作定制開發(fā)、品牌網(wǎng)站制作網(wǎng)站營銷、小程序開發(fā)、ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站