2

If I do:

sudo mysqldump --default-character-set=utf8 -u root -pwelcome1 mydb > dump.sql

I get:

-bash: dump.sql: Permission non accordée

However if I sudo to su first, it works fine. It seems that sudo does not propagate to the > command.

How can I fix this?

2

You can execute the bash shell (remember the full path) quoting "" all your command as argument with the option -c

sudo /bin/bash -c "mysqldump --default-character-set=utf8 -u root -pwelcome1 mydb > dump.sql"
  • ok, I didn't know that. It works, thanks. Why do I have to do that ? – Sam Jun 17 '14 at 22:03
  • I believe that when you invoke the command sudo as normal user, sudo calls what it follows, but the redirection of the output > is the redirection of the sudo command, so it belongs to the normal user. Of course it's only a way to do it. e.g. you can dump the file where you have the right to write. (... >/home/Sam/dump.sql) – Hastur Jun 17 '14 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.