PHP脚本备份数据库

发布于 2024-10-04 21:35:35 字数 672 浏览 3 评论 0原文

我尝试使用 PHP 备份 MySQL 数据库,但是当我设置备份路径时,我在运行脚本时收到另一个路径。

这是我的脚本:

$baseDir = 'backup/';
$db;
$table;
$server = $_SERVER['HTTP_HOST'] . substr($_SERVER['SCRIPT_NAME'],0,strrpos($_SERVER['SCRIPT_NAME'],'/'));

这是在备份功能内:

global $baseDir;
global $db;
global $server;
$backupFile = $server . "/$baseDir$db/$tab.sql";
$query = mysql_query("SELECT * INTO OUTFILE '$backupFile' FROM $tab");
if(!$query)
    echo "\t" .mysql_error() .PHP_EOL;
else
    echo " backuped." . PHP_EOL;

我得到的路径是:c:\wamp\bin\mysql\mysql5.1.36\data\localhost\db\backup\contact_keeper\accounts.sql > 错误代码:2(无法写入/创建)。

I have tried to backup my MySQL databases using PHP, yet when I set the path for the backup I receive another path when running the script.

this is my script:

$baseDir = 'backup/';
$db;
$table;
$server = $_SERVER['HTTP_HOST'] . substr($_SERVER['SCRIPT_NAME'],0,strrpos($_SERVER['SCRIPT_NAME'],'/'));

this is inside the backup function:

global $baseDir;
global $db;
global $server;
$backupFile = $server . "/$baseDir$db/$tab.sql";
$query = mysql_query("SELECT * INTO OUTFILE '$backupFile' FROM $tab");
if(!$query)
    echo "\t" .mysql_error() .PHP_EOL;
else
    echo " backuped." . PHP_EOL;

the path I get is: c:\wamp\bin\mysql\mysql5.1.36\data\localhost\db\backup\contact_keeper\accounts.sql with erroCode: 2 (can`t write/create).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

街角迷惘 2024-10-11 21:35:35

SELECT ... INTO OUTFILE 仅限于创建新文件。作为安全措施,它不能覆盖现有文件。另外,请确保 Windows 中运行 MySQL 的帐户对该 ...\backup\contact_keeper 目录具有写入权限。它可能只能读取/执行。

SELECT ... INTO OUTFILE is limited to only CREATING a new file. It cannot overwrite an existing file as a security measure. As well, make sure that the account that MySQL is running under in Windows has write permissions on that ...\backup\contact_keeper directory. It may have only read/execute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文