sudo mysqldump : Permission deniedHow to create a user with root privileges in bash?Problem accessing superuser with sudoTemporary Admin Status for System Maintenance on User AccountHow does the sudoers work?How can I get an interactive shell as another non-root user?Admin to root privilegesLooking for a better solution to execute a single sudo command when using a normal user account?Run sudo commands from standard accountPermission denied please try again ssh error

How often are there lunar eclipses on Jupiter

How can I run a realistic open-world game with vast power differences, without resulting in constant TPKs?

Puzzling is a Forte of Mine

Regulation for ETFs in the UK after the Brexit

What is the difference between "cat < filename" and "cat filename"?

Why can't sonic booms be heard at air shows?

How to upgrade SSD from HDD for my mac book pro

Are monosubstituted cyclopropanes achiral or chiral?

Old story about a man with tattoos that told stories

My professor changed a take-home test to an in-class test with no notice. Can I fight the grade?

Cheap and safe way to dim 100+ 60W Incandescent bulbs

Why didn't Philippine Airlines Flight 113 dump fuel prior to forced landing?

How can I offer my prayers to an atheist colleague facing a serious personal situation?

Journal editor made bad edits to my (accepted) paper - how do I respond?

Why is the Toffoli gate not sufficient for universal quantum computation?

How does "unlimited holidays" work in practice?

How can I justify this without determining the determinant?

How to differentiate landing on top of an object from falling down the side?

Short story about delivery truck organization existing only to support itself

Unstable manifolds of a Morse function give a CW complex

Pre-2000s novel about tourism through time travel

Plane ticket price went down by 40% two weeks after I booked it. Is there anything I can do to get a refund?

What is the rationale for single engine military aircraft?

Can the diameter be controled by the injectivity radius and the volume?



sudo mysqldump : Permission denied


How to create a user with root privileges in bash?Problem accessing superuser with sudoTemporary Admin Status for System Maintenance on User AccountHow does the sudoers work?How can I get an interactive shell as another non-root user?Admin to root privilegesLooking for a better solution to execute a single sudo command when using a normal user account?Run sudo commands from standard accountPermission denied please try again ssh error






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









4


















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












  • That is because even though sudo gives you elevated privileges it doesn't change the user that you are trying to access the db with. Meaning if you are trying it with sudo mysqldump it is still trying it with your user but with elevated permissions, but with sudo su you become root - a user which exists in the DB by default - which makes it work.

    – Ziazis
    Sep 19 at 7:07

















4


















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












  • That is because even though sudo gives you elevated privileges it doesn't change the user that you are trying to access the db with. Meaning if you are trying it with sudo mysqldump it is still trying it with your user but with elevated permissions, but with sudo su you become root - a user which exists in the DB by default - which makes it work.

    – Ziazis
    Sep 19 at 7:07













4













4









4








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

511 gold badge1 silver badge3 bronze badges




511 gold badge1 silver badge3 bronze badges















  • 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












  • That is because even though sudo gives you elevated privileges it doesn't change the user that you are trying to access the db with. Meaning if you are trying it with sudo mysqldump it is still trying it with your user but with elevated permissions, but with sudo su you become root - a user which exists in the DB by default - which makes it work.

    – Ziazis
    Sep 19 at 7:07

















  • 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












  • That is because even though sudo gives you elevated privileges it doesn't change the user that you are trying to access the db with. Meaning if you are trying it with sudo mysqldump it is still trying it with your user but with elevated permissions, but with sudo su you become root - a user which exists in the DB by default - which makes it work.

    – Ziazis
    Sep 19 at 7:07
















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














That is because even though sudo gives you elevated privileges it doesn't change the user that you are trying to access the db with. Meaning if you are trying it with sudo mysqldump it is still trying it with your user but with elevated permissions, but with sudo su you become root - a user which exists in the DB by default - which makes it work.

– Ziazis
Sep 19 at 7:07





That is because even though sudo gives you elevated privileges it doesn't change the user that you are trying to access the db with. Meaning if you are trying it with sudo mysqldump it is still trying it with your user but with elevated permissions, but with sudo su you become root - a user which exists in the DB by default - which makes it work.

– Ziazis
Sep 19 at 7:07










7 Answers
7






active

oldest

votes


















3



















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

































    3



















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



    $ sudo su
    # mysqldump database> database.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

































        1



















        This did work for me:



        mysqldump -u db_user -p --databases db_name > /home/$USER/my.dump.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



















            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



























                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/4.0/"u003ecc by-sa 4.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


























                7 Answers
                7






                active

                oldest

                votes








                7 Answers
                7






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                3



















                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






























                  3



















                  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




























                    3















                    3











                    3









                    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

                    312 bronze badges




                    312 bronze badges


























                        3



















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



                        $ sudo su
                        # mysqldump database> database.sql





                        share|improve this answer






























                          3



















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



                          $ sudo su
                          # mysqldump database> database.sql





                          share|improve this answer




























                            3















                            3











                            3









                            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

                            311 bronze badge




                            311 bronze badge
























                                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ʒɑ

                                    80.1k88 gold badges224 silver badges309 bronze badges




                                    80.1k88 gold badges224 silver badges309 bronze badges
























                                        1



















                                        This did work for me:



                                        mysqldump -u db_user -p --databases db_name > /home/$USER/my.dump.sql





                                        share|improve this answer
































                                          1



















                                          This did work for me:



                                          mysqldump -u db_user -p --databases db_name > /home/$USER/my.dump.sql





                                          share|improve this answer






























                                            1















                                            1











                                            1









                                            This did work for me:



                                            mysqldump -u db_user -p --databases db_name > /home/$USER/my.dump.sql





                                            share|improve this answer
















                                            This did work for me:



                                            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








                                            edited Sep 18 at 23:42









                                            Pablo A

                                            4,5953 gold badges23 silver badges50 bronze badges




                                            4,5953 gold badges23 silver badges50 bronze badges










                                            answered Sep 18 at 17:13









                                            Pish PeterPish Peter

                                            111 bronze badge




                                            111 bronze badge
























                                                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 bronze badges




                                                                    1012 bronze badges































                                                                        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

                                                                        Tamil (spriik) Luke uk diar | Nawigatjuun

                                                                        Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                                                                        Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?