Reputation: 1
I'm try to do a dump of my db in this way:
$output = NULL;
$command = 'mysqldump -u $dbuser -h localhost -p$password $dbname > dump.sql';
passthru($command, $output);
I've tried in this way too:
$command = 'mysqldump -u $dbuser -h localhost -p$password $dbname > dump.sql';
exec($command);
In both ways it create an empty dump.sql
Where am I wrong? Can you help me?
Upvotes: 0
Views: 2804
Reputation: 1484
I also faced the same problem, and fixed it by adding password in my.ini file
C:\wamp64\bin\mysql\mysql5.7.28\my.ini
search for [client]
attribute and put username & password below it as
[client]
user="root"
password=""
and then restart wamp then you do not need to mention -p in mysqldump command
mysqldump -u dbUserName dbName > "C:\folder1\folder2\backup.sql"
Upvotes: 0
Reputation: 184
I can not say exactly but if you are using single quotes, php variables wont be replaced with real values. You should use double quotes instead of single quotes.
Like $command="mysqldump -u $dbuser -h localhost -p$password $dbname > dump.sql";
Try to print command before execute to make sure that values are replaced with variables.
Let me know if that doesnt work, will give u an option to debug more accurately.
Try with below and let me know the output.
$command = "mysqldump -u $dbuser -h localhost -p$password $dbname > dump.sql 2>&1";
exec($command, $output);
echo '<pre>';print_r($output);exit;
Upvotes: 1
Reputation: 41
I would suggest you to make use of the --single-transaction flag while using mysqldump.
mysqldump --single-transaction -u$dbuser -hlocalhost -p$password $dbname > dump.sql
With that said, I would suspect either a timeout (PHP or MySQL) or a out-of-memory error.
How did you executed your script? Browser or CLI?
Upvotes: 4