www.国产视频,一级看片免费视频囗交动图,波多野结衣高清无码中文456,中国一级特黄特级毛片,69mmWWW路cOm,天天摸夜夜摸黄片,aaaaaaaaa在线观看

綠色資源網(wǎng):您身邊最放心的安全下載站! 最新軟件|熱門排行|軟件分類|軟件專題|論壇轉帖|廠商大全

綠色資源網(wǎng)

技術教程
您的位置:首頁數(shù)據(jù)庫類MySQL → 如何導出mysql數(shù)據(jù)庫到sql文件

如何導出mysql數(shù)據(jù)庫到sql文件

我要評論 2012/04/24 14:11:42 來源:綠色資源網(wǎng) 編輯:downcc.com [ ] 評論:0 點擊:696次

你的用戶可能會要求你增加一個導出整個數(shù)據(jù)庫到sql文件的一個選項,當然phpMyAdmin或者Navicat可以做到這些,但是您的用戶可能想要更簡單的方法。

創(chuàng)建一個名為backup.php的新文件,復制粘貼以下代碼。如果需要的話,編輯數(shù)據(jù)庫連接設置和mysqldump路徑。為你的應用添加一個backup.php的超級連接。

<a href="back.php">export the whole database</a>

請注意:為了保存和壓縮轉儲文件,該腳本需要一個可寫權限。如果你的腳本沒有可寫權限請使用第二個版本,唯一的缺點是無法壓縮轉儲文件。

有壓縮版本需要可寫權限:

<?php
 
$username = "root"; 
$password = ""; 
$hostname = "localhost"; 
$dbname   = "cars";
 
// if mysqldump is on the system path you do not need to specify the full path
// simply use "mysqldump --add-drop-table ..." in this case
$dumpfname = $dbname . "_" . date("Y-m-d_H-i-s").".sql";
$command = "C:\\xampp\\mysql\\bin\\mysqldump --add-drop-table --host=$hostname
    --user=$username ";
if ($password) 
        $command.= "--password=". $password ." "; 
$command.= $dbname;
$command.= " > " . $dumpfname;
system($command);
 
// zip the dump file
$zipfname = $dbname . "_" . date("Y-m-d_H-i-s").".zip";
$zip = new ZipArchive();
if($zip->open($zipfname,ZIPARCHIVE::CREATE)) 
{
   $zip->addFile($dumpfname,$dumpfname);
   $zip->close();
}
 
// read zip file and send it to standard output
if (file_exists($zipfname)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($zipfname));
    flush();
    readfile($zipfname);
    exit;
}
?>

沒有壓縮,不需要可寫權限:

<?php
ob_start();
 
$username = "root"; 
$password = ""; 
$hostname = "localhost"; 
$dbname   = "cars";
 
// if mysqldump is on the system path you do not need to specify the full path
// simply use "mysqldump --add-drop-table ..." in this case
$command = "C:\\xampp\\mysql\\bin\\mysqldump --add-drop-table --host=$hostname
    --user=$username ";
if ($password) 
        $command.= "--password=". $password ." "; 
$command.= $dbname;
system($command);
 
$dump = ob_get_contents(); 
ob_end_clean();
 
// send dump file to the output
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($dbname . "_" . 
    date("Y-m-d_H-i-s").".sql"));
flush();
echo $dump;
exit();]]>
?>

原文地址:http://webcheatsheet.com/php/how_to_create_a_dump_of_mysql_database_in_one_click.php

關鍵詞:mysql數(shù)據(jù)庫

閱讀本文后您有什么感想? 已有 人給出評價!

  • 1 歡迎喜歡
  • 1 白癡
  • 1 拜托
  • 1 哇
  • 1 加油
  • 1 鄙視