php生成的mysql备份
来源:互联网 发布:淘宝app修改评价 编辑:程序博客网 时间:2024/05/21 03:55
需要可写权限的backup.php文件
执行的时候,会导出zip压缩后的sql文件,所以此代码所在文件夹需要可写的权限。
<?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代码,缺点是导出的sql文件不会被zip压缩。
01
<?php
02
ob_start();
03
04
$username
=
"root"
;
05
$password
=
""
;
06
$hostname
=
"localhost"
;
07
$dbname
=
"cars"
;
08
09
// if mysqldump is on the system path you do not need to specify the full path
10
// simply use "mysqldump --add-drop-table ..." in this case
11
$command
= "C:\\xampp\\mysql\\bin\\mysqldump --add-drop-table --host=
$hostname
12
--user=
$username
";
13
if
(
$password
)
14
$command
.=
"--password="
.
$password
.
" "
;
15
$command
.=
$dbname
;
16
system(
$command
);
17
18
$dump
= ob_get_contents();
19
ob_end_clean();
20
21
// send dump file to the output
22
header(
'Content-Description: File Transfer'
);
23
header(
'Content-Type: application/octet-stream'
);
24
header(
'Content-Disposition: attachment; filename='
.
basename
(
$dbname
.
"_"
.
25
date
(
"Y-m-d_H-i-s"
).
".sql"
));
26
flush
();
27
echo
$dump
;
28
exit
();]]>
29
?>
- php生成的mysql备份
- php mysqldump备份mysql win2003下 不生成, 生成为空的问题
- php备份备份mysql
- 用PHP备份mysql数据库的方法
- PHP 备份 Mysql 数据库的实现
- PHP备份/还原MySQL数据库的代码
- PHP备份/还原MySQL数据库的代码
- mysql自动生成备份
- PHP实现MYSQL备份
- PHP备份MYSQL数据库
- PHP备份MySQL数据库
- php实现mysql备份
- php实现mysql备份
- php mysql数据库备份
- mysql生成纯文本文件备份
- 生成MySQL数据字典的PHP脚本
- php实现备份mysql数据库
- php实现备份mysql数据库
- The calculation of GPA 1202
- STL之list双向链表容器入门
- 求解线性方程组之全选主元高斯消元法
- 驾照
- SQLite介绍、学习笔记、性能测试
- php生成的mysql备份
- CI20.2--洗牌算法
- js正则函数match、exec、test、search、replace、split使用介绍集合
- 利用Oracle执行计划机制提高查询性能
- 【练习04】 字典树 1002 Flying to the Mars
- 求解线性方程组之LU分解
- Android平台第三方应用分享到微信开发
- 性能测试面面观——HP性能测试专家宗刚访谈
- cocos2d-x过程动作CCProgressTo示例学习笔记