MySQLdump使用PHP但不使用命令行来清空文件? [英] MySQLdump empty file using PHP but not command line?

查看:118
本文介绍了MySQLdump使用PHP但不使用命令行来清空文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mysql的备份脚本.它的一种变体曾经可以工作,但是自php4以来我还没有看过它.它返回一个空文件.奇怪的是,如果我转到命令行并使用EXACT相同的命令,则会得到期望的文件.

I'm playing around with a backup script for mysql. A variation of this used to work, but I haven't looked at it since php4. It's returning an empty file. The weird thing is that if I go to the command line and use the EXACT same command, I get the file I'm expecting.

我在互联网上闲逛,找不到任何东西……想法?

I've poked around the internet and can't find anything... thoughts?

错误代码?

$db_host='localhost';
$db_user='root';
$db_pass='root';
$db_name='gakkou';
$dir='backups';
$file_list=scandir($dir);
if(count($file_list)>10) unlink($dir.'/'.$file_list[2]); //delete old file
$prefix=date("YmdHi").'_';
$command='mysqldump -u'.$db_user.' --password="'.$db_pass.'" --databases '.$db_name.' | gzip > '.$dir.'/'.$prefix.'_backup.sql.gzip';
exec($command,$output,$return_val);

这很完美:mysqldump -uroot -proot -hlocalhost gakkou > /webdocs/gakkou/backups/mysql_backup.sql,它与php文件执行的命令完全相同(文件名除外).

This works perfectly: mysqldump -uroot -proot -hlocalhost gakkou > /webdocs/gakkou/backups/mysql_backup.sql and it is exactly the same as the command the php file executes (except for the file name).

针对感兴趣的任何人更新了工作代码.原来这是两个独立的问题.使用MAMP,我需要指定路径/Applications/MAMP/Library/bin/mysqldump.然后在生产服务器上,疯狂的密码破坏了作品.

updated with working code for anyone interested. This turned out to be two separate issues. Using MAMP, I needed to specify the path /Applications/MAMP/Library/bin/mysqldump. Then on the production server the crazy password gummed up the works.

推荐答案

确定.终于明白了.我的超级愚蠢密码使mysqldump混乱,因为它带有&"在里面.不必更改密码.我只是将密码放在括号中:--password="'.$db_pass.'"现在,它可以正常工作了.浪费了很多时间... @MarcB,非常感谢您的帮助.不知道如何返回错误,那绝对是最大的障碍.

OK. FINALLY got it figured out. My super stupid password was messing with mysqldump because it had an "&" in it. Didn't have to change the password. I just enclosed the password in parentheses: --password="'.$db_pass.'" Now it works as expected. So many hours wasted... @MarcB, thank you so much for your help. Didn't know how to return the errors and that was definitely the biggest roadblock.

这篇关于MySQLdump使用PHP但不使用命令行来清空文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆