Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysqldump doesn't run correctly

I write some code with PHP to backup database.

Here my code:

exec("mysqldump --opt -h localhost -u root test > mydb.sql");

But I get 0-byte in my file (mydb.sql). I also run with passthru(), system(), but it still gets 0-byte.

I try to use command. It works.

I use the lastest XAMPP for my localhost.

So, how can I do to make it works correctly?

like image 401
KimKha Avatar asked Jan 19 '26 00:01

KimKha


1 Answers

It's likely a permissions issue, or the fact you're not passing a password. To see errors, route STDERR to STDOUT using 2>&1

exec("mysqldump --opt -h localhost -u root test > mydb.sql 2>&1", $output);
print_r($output);

This will show you the errors you'd normally see on the command line.

like image 198
Andy Avatar answered Jan 21 '26 15:01

Andy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!