1

I need to run this command in php to get my DB backup automatic.

<?php
    $output = exec("C:/xampp/mysql/bin/mysqldump -u root -p > my_db.sql"); 
?>

need help

2
  • this command work in CMD but not in PHP exec Commented Nov 22, 2018 at 6:00
  • mysqldump: Got error: 1045: "Access denied for user 'root'@'localhost' (using password: YES)" when trying to connect Commented Nov 22, 2018 at 6:49

1 Answer 1

1

The -p flag requires you to enter a password for the user. Since you are using the default configuration (no password) you should remove the flag.

exec("C:/xampp/mysql/bin/mysqldump -u root > my_db.sql");

with that flag it will just hang waiting for you to pass in the password.

If your user had a password you could do:

$output = exec("C:/xampp/mysql/bin/mysqldump -u root -pMyPassword > my_db.sql");

but this is bad idea because if the script is ever exposed your root password will be known.

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

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.