0

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?

4
  • 1
    If you echo/log that $command and run it from the command line, does it work for you? Commented Apr 3, 2019 at 15:06
  • emvee-solutions.com/blog/… Commented Apr 3, 2019 at 15:46
  • @RonakRathod thank you. Is there a way to import by magento function this dump? Commented Apr 5, 2019 at 13:48
  • @RonakRathod Is there a way to import by magento function this dump? Commented Apr 5, 2019 at 14:46

3 Answers 3

4

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?

Sign up to request clarification or add additional context in comments.

1 Comment

I've tried with your command by CLI but it sees a password character (@) as a separator and then returns an error on the command.
1

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;

1 Comment

Updated my comment to debug the command. Try it and let me know the output.
0

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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.