sudo mysqldump : Permission denied












3















I am trying to run



sudo mysqldump


with user account but I get : Permission denied message



If I switch to sudo su then it works.



The question is why sudo gives permission denied? should i give some other privileges on my user account?










share|improve this question

























  • The problem is that if i login with root user i can take a mysqldump without problem. But if i login with user account i get permission denied and i must run sudo su first.

    – Kapa
    Nov 17 '13 at 14:55


















3















I am trying to run



sudo mysqldump


with user account but I get : Permission denied message



If I switch to sudo su then it works.



The question is why sudo gives permission denied? should i give some other privileges on my user account?










share|improve this question

























  • The problem is that if i login with root user i can take a mysqldump without problem. But if i login with user account i get permission denied and i must run sudo su first.

    – Kapa
    Nov 17 '13 at 14:55
















3












3








3








I am trying to run



sudo mysqldump


with user account but I get : Permission denied message



If I switch to sudo su then it works.



The question is why sudo gives permission denied? should i give some other privileges on my user account?










share|improve this question
















I am trying to run



sudo mysqldump


with user account but I get : Permission denied message



If I switch to sudo su then it works.



The question is why sudo gives permission denied? should i give some other privileges on my user account?







users privileges






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '13 at 12:52







user164718

















asked Nov 17 '13 at 12:08









KapaKapa

21113




21113













  • The problem is that if i login with root user i can take a mysqldump without problem. But if i login with user account i get permission denied and i must run sudo su first.

    – Kapa
    Nov 17 '13 at 14:55





















  • The problem is that if i login with root user i can take a mysqldump without problem. But if i login with user account i get permission denied and i must run sudo su first.

    – Kapa
    Nov 17 '13 at 14:55



















The problem is that if i login with root user i can take a mysqldump without problem. But if i login with user account i get permission denied and i must run sudo su first.

– Kapa
Nov 17 '13 at 14:55







The problem is that if i login with root user i can take a mysqldump without problem. But if i login with user account i get permission denied and i must run sudo su first.

– Kapa
Nov 17 '13 at 14:55












6 Answers
6






active

oldest

votes


















2














Try to save dump into user home directory



e.g. mysqldump -u {db_user} -p --databases {db_name} > /home/{user}/my.dump.sql






share|improve this answer































    1














    mysqldump will need a password for the mysql user root. If you don't supply that password it won't work, sudo or no sudo.



    mysqldump can look at your .my.cnf file to get the password, and it'll get that from the user runing the mysqldump command. So, if the Linux root user has a .my.cnf configured with a password in it, then yes, sudo will help. However, if the mysql root user has a password and it's not configured in any .my.cnf's then sudo won't help.



    You could add the mysql root user and password to your own user's .my.cnf and then you don't need sudo either, but that's a security risk.



    As the other answers point out as well, you might need sudo to write the output somewhere that root (Linux, not mysql) owns.



    Lastly, you don't tell us which user is executing the script, if it's in root's crontab (for example), then sudo will not be necessary, although you may still need a .my.cnf to provide the password.



    If your mysql root user has no password set, then the only issue is writing the output, in which case sudo is required if you don't run the script as root.



    If you run the script as root (for example, as a script in /etc/cron.daily) then you should not use sudo within the script, irrespective of all the above



    credit






    share|improve this answer































      0














      Make sure you command destination path mentioned.



      For eg: sudo mysql -u YourUsername -p DatabaseName > ~/Path/Where/you/Want/The/Dump/FiletoBe/Kept/dumpfile.sql






      share|improve this answer































        0














        mysqldump requires username of the current user else it will take root as default. When you do aisi su, you automatically provide root access. Try this with your username in place of user. mysqldump -u user -p Enter password when prompt.






        share|improve this answer































          0














          Add write permissions of the folder you want to dump the sql file in:



          sudo chmod 755 folder_url



          and run:



          mysqldump -u user -p db_name > db_dump.sql






          share|improve this answer































            0














            mysqldump on a production server does not work with sudo. Please try this:



            $ sudo su
            # mysqldump database> database.sql





            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "89"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f378339%2fsudo-mysqldump-permission-denied%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              6 Answers
              6






              active

              oldest

              votes








              6 Answers
              6






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              Try to save dump into user home directory



              e.g. mysqldump -u {db_user} -p --databases {db_name} > /home/{user}/my.dump.sql






              share|improve this answer




























                2














                Try to save dump into user home directory



                e.g. mysqldump -u {db_user} -p --databases {db_name} > /home/{user}/my.dump.sql






                share|improve this answer


























                  2












                  2








                  2







                  Try to save dump into user home directory



                  e.g. mysqldump -u {db_user} -p --databases {db_name} > /home/{user}/my.dump.sql






                  share|improve this answer













                  Try to save dump into user home directory



                  e.g. mysqldump -u {db_user} -p --databases {db_name} > /home/{user}/my.dump.sql







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 5 '18 at 9:53









                  Dima KurtashDima Kurtash

                  212




                  212

























                      1














                      mysqldump will need a password for the mysql user root. If you don't supply that password it won't work, sudo or no sudo.



                      mysqldump can look at your .my.cnf file to get the password, and it'll get that from the user runing the mysqldump command. So, if the Linux root user has a .my.cnf configured with a password in it, then yes, sudo will help. However, if the mysql root user has a password and it's not configured in any .my.cnf's then sudo won't help.



                      You could add the mysql root user and password to your own user's .my.cnf and then you don't need sudo either, but that's a security risk.



                      As the other answers point out as well, you might need sudo to write the output somewhere that root (Linux, not mysql) owns.



                      Lastly, you don't tell us which user is executing the script, if it's in root's crontab (for example), then sudo will not be necessary, although you may still need a .my.cnf to provide the password.



                      If your mysql root user has no password set, then the only issue is writing the output, in which case sudo is required if you don't run the script as root.



                      If you run the script as root (for example, as a script in /etc/cron.daily) then you should not use sudo within the script, irrespective of all the above



                      credit






                      share|improve this answer




























                        1














                        mysqldump will need a password for the mysql user root. If you don't supply that password it won't work, sudo or no sudo.



                        mysqldump can look at your .my.cnf file to get the password, and it'll get that from the user runing the mysqldump command. So, if the Linux root user has a .my.cnf configured with a password in it, then yes, sudo will help. However, if the mysql root user has a password and it's not configured in any .my.cnf's then sudo won't help.



                        You could add the mysql root user and password to your own user's .my.cnf and then you don't need sudo either, but that's a security risk.



                        As the other answers point out as well, you might need sudo to write the output somewhere that root (Linux, not mysql) owns.



                        Lastly, you don't tell us which user is executing the script, if it's in root's crontab (for example), then sudo will not be necessary, although you may still need a .my.cnf to provide the password.



                        If your mysql root user has no password set, then the only issue is writing the output, in which case sudo is required if you don't run the script as root.



                        If you run the script as root (for example, as a script in /etc/cron.daily) then you should not use sudo within the script, irrespective of all the above



                        credit






                        share|improve this answer


























                          1












                          1








                          1







                          mysqldump will need a password for the mysql user root. If you don't supply that password it won't work, sudo or no sudo.



                          mysqldump can look at your .my.cnf file to get the password, and it'll get that from the user runing the mysqldump command. So, if the Linux root user has a .my.cnf configured with a password in it, then yes, sudo will help. However, if the mysql root user has a password and it's not configured in any .my.cnf's then sudo won't help.



                          You could add the mysql root user and password to your own user's .my.cnf and then you don't need sudo either, but that's a security risk.



                          As the other answers point out as well, you might need sudo to write the output somewhere that root (Linux, not mysql) owns.



                          Lastly, you don't tell us which user is executing the script, if it's in root's crontab (for example), then sudo will not be necessary, although you may still need a .my.cnf to provide the password.



                          If your mysql root user has no password set, then the only issue is writing the output, in which case sudo is required if you don't run the script as root.



                          If you run the script as root (for example, as a script in /etc/cron.daily) then you should not use sudo within the script, irrespective of all the above



                          credit






                          share|improve this answer













                          mysqldump will need a password for the mysql user root. If you don't supply that password it won't work, sudo or no sudo.



                          mysqldump can look at your .my.cnf file to get the password, and it'll get that from the user runing the mysqldump command. So, if the Linux root user has a .my.cnf configured with a password in it, then yes, sudo will help. However, if the mysql root user has a password and it's not configured in any .my.cnf's then sudo won't help.



                          You could add the mysql root user and password to your own user's .my.cnf and then you don't need sudo either, but that's a security risk.



                          As the other answers point out as well, you might need sudo to write the output somewhere that root (Linux, not mysql) owns.



                          Lastly, you don't tell us which user is executing the script, if it's in root's crontab (for example), then sudo will not be necessary, although you may still need a .my.cnf to provide the password.



                          If your mysql root user has no password set, then the only issue is writing the output, in which case sudo is required if you don't run the script as root.



                          If you run the script as root (for example, as a script in /etc/cron.daily) then you should not use sudo within the script, irrespective of all the above



                          credit







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 17 '13 at 13:47









                          rɑːdʒɑrɑːdʒɑ

                          58.6k85218302




                          58.6k85218302























                              0














                              Make sure you command destination path mentioned.



                              For eg: sudo mysql -u YourUsername -p DatabaseName > ~/Path/Where/you/Want/The/Dump/FiletoBe/Kept/dumpfile.sql






                              share|improve this answer




























                                0














                                Make sure you command destination path mentioned.



                                For eg: sudo mysql -u YourUsername -p DatabaseName > ~/Path/Where/you/Want/The/Dump/FiletoBe/Kept/dumpfile.sql






                                share|improve this answer


























                                  0












                                  0








                                  0







                                  Make sure you command destination path mentioned.



                                  For eg: sudo mysql -u YourUsername -p DatabaseName > ~/Path/Where/you/Want/The/Dump/FiletoBe/Kept/dumpfile.sql






                                  share|improve this answer













                                  Make sure you command destination path mentioned.



                                  For eg: sudo mysql -u YourUsername -p DatabaseName > ~/Path/Where/you/Want/The/Dump/FiletoBe/Kept/dumpfile.sql







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Sep 7 '16 at 20:45









                                  user591987user591987

                                  1




                                  1























                                      0














                                      mysqldump requires username of the current user else it will take root as default. When you do aisi su, you automatically provide root access. Try this with your username in place of user. mysqldump -u user -p Enter password when prompt.






                                      share|improve this answer




























                                        0














                                        mysqldump requires username of the current user else it will take root as default. When you do aisi su, you automatically provide root access. Try this with your username in place of user. mysqldump -u user -p Enter password when prompt.






                                        share|improve this answer


























                                          0












                                          0








                                          0







                                          mysqldump requires username of the current user else it will take root as default. When you do aisi su, you automatically provide root access. Try this with your username in place of user. mysqldump -u user -p Enter password when prompt.






                                          share|improve this answer













                                          mysqldump requires username of the current user else it will take root as default. When you do aisi su, you automatically provide root access. Try this with your username in place of user. mysqldump -u user -p Enter password when prompt.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Mar 5 '17 at 13:30









                                          collinxcollinx

                                          1




                                          1























                                              0














                                              Add write permissions of the folder you want to dump the sql file in:



                                              sudo chmod 755 folder_url



                                              and run:



                                              mysqldump -u user -p db_name > db_dump.sql






                                              share|improve this answer




























                                                0














                                                Add write permissions of the folder you want to dump the sql file in:



                                                sudo chmod 755 folder_url



                                                and run:



                                                mysqldump -u user -p db_name > db_dump.sql






                                                share|improve this answer


























                                                  0












                                                  0








                                                  0







                                                  Add write permissions of the folder you want to dump the sql file in:



                                                  sudo chmod 755 folder_url



                                                  and run:



                                                  mysqldump -u user -p db_name > db_dump.sql






                                                  share|improve this answer













                                                  Add write permissions of the folder you want to dump the sql file in:



                                                  sudo chmod 755 folder_url



                                                  and run:



                                                  mysqldump -u user -p db_name > db_dump.sql







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Nov 11 '17 at 13:33









                                                  WilliamWilliam

                                                  1012




                                                  1012























                                                      0














                                                      mysqldump on a production server does not work with sudo. Please try this:



                                                      $ sudo su
                                                      # mysqldump database> database.sql





                                                      share|improve this answer




























                                                        0














                                                        mysqldump on a production server does not work with sudo. Please try this:



                                                        $ sudo su
                                                        # mysqldump database> database.sql





                                                        share|improve this answer


























                                                          0












                                                          0








                                                          0







                                                          mysqldump on a production server does not work with sudo. Please try this:



                                                          $ sudo su
                                                          # mysqldump database> database.sql





                                                          share|improve this answer













                                                          mysqldump on a production server does not work with sudo. Please try this:



                                                          $ sudo su
                                                          # mysqldump database> database.sql






                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Feb 20 at 3:31









                                                          Bryan Zavala ValvidiaBryan Zavala Valvidia

                                                          1




                                                          1






























                                                              draft saved

                                                              draft discarded




















































                                                              Thanks for contributing an answer to Ask Ubuntu!


                                                              • Please be sure to answer the question. Provide details and share your research!

                                                              But avoid



                                                              • Asking for help, clarification, or responding to other answers.

                                                              • Making statements based on opinion; back them up with references or personal experience.


                                                              To learn more, see our tips on writing great answers.




                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function () {
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f378339%2fsudo-mysqldump-permission-denied%23new-answer', 'question_page');
                                                              }
                                                              );

                                                              Post as a guest















                                                              Required, but never shown





















































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown

































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown







                                                              Popular posts from this blog

                                                              flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                                                              Mangá

                                                              Eduardo VII do Reino Unido