/    Sign up×
Community /Pin to ProfileBookmark

mysqldump not dumping

Hi all,
I’m trying to get my head around mysqldump, and seem to be missing something…

this…

[code=php]$targetfile = “/tmp/backup.sql”;
$dump = “mysqldump –opt -h localhost -u myuser -p mypassword $db > $targetfile”;
system($dump);[/code]

creates an empty file “backup.sql” in the “/tmp” folder (there [B]is[/B] data in the db).

And can I have the mysqldump output sent directly to a php variable instead of a file? I’ve found that mysqldump creates lines that are too long, so I want to replace “),(” with “),rn(” in the output. Perhaps something like
$output = system($dump);
might work?

Thanks
CTB

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@chazzyMar 06.2008 — the syntax is wrong. should be

<i>
</i>mysqldump --opt -h localhost -u myuser -pmypassword $db &gt; $targetfile


MySQL requires you to put the -p and password together, no spaces.
Copy linkTweet thisAlerts:
@chestertbauthorMar 06.2008 — thanks chazzy.

that didn't fix it.

i'm still getting empty files.

anything else?
Copy linkTweet thisAlerts:
@NogDogMar 06.2008 — Try adding the STDERR output to your output to see if there is any error message that will point out the problem:
[code=php]
$dump = "mysqldump --opt -h localhost -u myuser -pmypassword $db 2>&1 > $targetfile";
[/code]
Copy linkTweet thisAlerts:
@chestertbauthorMar 06.2008 — Thanks Dog.

It seems Windoze doesn't recognise mysqldump as a command.

I moved the script to the server andnthat error's gone, only to be replaced by another...

Here's the current script snippet
[code=php] $db = $connect['data'];

$targetfile = "/tmp/".$db."_".$sqldate.".sql";
$dump = "mysqldump --opt -h localhost --user=username --password=password ".$db." > ".$targetfile;

system($dump);[/code]

but nothing appears in my server /tmp folder (which has permissions set to be read/writable by anyone).
Copy linkTweet thisAlerts:
@chazzyMar 07.2008 — try using the full path to mysqldump. Don't assume that "nobody" on your server has the same $PATH as you.
×

Success!

Help @chestertb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...