I have gone over several posts where people have managed to have their issues resolved but unfortunately no success for me. I am using wamp on windows and my php file looks as follows
<?php
include_once("config.php");
$_user = "username";
$_pass = "password";
$_db = "dbname";
$command = 'C:\wamp\bin\mysql\mysql5.6.17\bin\mysqldump -u '.$_user.' -p'.$_pass.' '.$_db.' > test.sql';
exec($command);
echo "<br />".$command;
?>
A file name test.sql is created but it is of 0 bytes. I also tried changing mysqldump to mysqldump.exe but no success. Prior to this I was trying by not defining path of mysqldump in that case the process never used to end. Now the process ends immediately but the file is empty.
I've had the same problem too and was pulling my hair because none of the solutions I found worked for me.
Finally I tried running the command from cmd (windows' command prompt) and found out that Windows couldn't find the path to that MySQL command.
Anyway, Long story short, here's what worked for me and you can get rid of the absolute path to mydsqldump command:
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
In your code, remove the absolute path to your (C:\\wamp\\bin\\mysql\\mysql5.6.17\\bin) mysqldump command, leaving only mysqldump without any path. Below is what works for me:
$command = 'mysqldump --opt --host=YOUR_HOST --password="YOUR_PASSWORD" --user=YOUR_DB_USER --databases YOUR_DB_NAME > PATH_TO_FILE/FILE_NAME.sql';
Replace capitalized part in the code above with your own information
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.