PHP使用外部命令导出数据库,备份到服务器并下载到本地
<?php
// $dumpFileName目录要有可写权限
$DbHost = ‘localhost‘;
$DbUser = ‘root‘;
$DbPwd = ‘123456‘;
$DbName = ‘a‘;
$fileName = $DbName . ‘_MySQL_data_backup_‘ . date(‘YmdHis) . ‘.sql‘;
$dumpFileName= "/var/$fileName";
header("Content-Disposition: attachment; filename=" . $fileName);
header("Content-type: application/octet-stream");
header("Pragma:no-cache");
header("Expires:0");
echo `mysqldump -h $DbHost -u$DbUser -p$DbPwd $DbName > $dumpFileName`;
$hd = fopen($dumpFileName, ‘rb‘);
echo fread($hd, filesize($dumpFileName));
fclose($hd);
?>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。