PHP脚本备份数据库
我尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.