Which is the easiest way to reset the mysql root password?











up vote
6
down vote

favorite
1












In the past there has been sudo /etc/init.d/mysql reset-password, (1) is manually restarting and setting the password with an sql command again required? (2)



(1) http://www.ubuntugeek.com/reset-the-root-password-on-mysql.html
(2) http://www.howtoforge.com/reset-forgotten-mysql-root-password










share|improve this question




















  • 2




    second link look like the way to go
    – Panther
    Dec 23 '11 at 5:25















up vote
6
down vote

favorite
1












In the past there has been sudo /etc/init.d/mysql reset-password, (1) is manually restarting and setting the password with an sql command again required? (2)



(1) http://www.ubuntugeek.com/reset-the-root-password-on-mysql.html
(2) http://www.howtoforge.com/reset-forgotten-mysql-root-password










share|improve this question




















  • 2




    second link look like the way to go
    – Panther
    Dec 23 '11 at 5:25













up vote
6
down vote

favorite
1









up vote
6
down vote

favorite
1






1





In the past there has been sudo /etc/init.d/mysql reset-password, (1) is manually restarting and setting the password with an sql command again required? (2)



(1) http://www.ubuntugeek.com/reset-the-root-password-on-mysql.html
(2) http://www.howtoforge.com/reset-forgotten-mysql-root-password










share|improve this question















In the past there has been sudo /etc/init.d/mysql reset-password, (1) is manually restarting and setting the password with an sql command again required? (2)



(1) http://www.ubuntugeek.com/reset-the-root-password-on-mysql.html
(2) http://www.howtoforge.com/reset-forgotten-mysql-root-password







password mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 23 '11 at 4:07









Jorge Castro

35.6k105422617




35.6k105422617










asked Dec 23 '11 at 4:06









WhiteZebra

3112




3112








  • 2




    second link look like the way to go
    – Panther
    Dec 23 '11 at 5:25














  • 2




    second link look like the way to go
    – Panther
    Dec 23 '11 at 5:25








2




2




second link look like the way to go
– Panther
Dec 23 '11 at 5:25




second link look like the way to go
– Panther
Dec 23 '11 at 5:25










6 Answers
6






active

oldest

votes

















up vote
5
down vote













There's also an administrative user equivalent to root: debian-sys-maint. You can use this account to reset root's password. You can find its password in /etc/mysql/debian.cnf






share|improve this answer




























    up vote
    4
    down vote













    You could create a sql file say /root/mysql.reset.sql with the content:



    UPDATE mysql.user SET Password=PASSWORD('yourpassword') WHERE User='root';
    FLUSH PRIVILEGES;


    And just call:



    mysqld_safe --init-file=/root/mysql.reset.sql


    Will be very helpful if you are in a habit of forgetting passwords often.






    share|improve this answer






























      up vote
      1
      down vote













      sudo dpkg-reconfigure mysql-server-5.5


      you can use tab complete after mysql-server- if you're using a different version of mysql.






      share|improve this answer




























        up vote
        1
        down vote













        tumbleweed's answer was the only one that helped me. I was dealing with what could possibly have been a corrupted root user and none of the standard methods resolved the issue of not being able to log in as root.



        Using the debian-sys-maint user, I was able to finally log into MySQL with escalated privileges and even then resetting the root password did not work.



        However, I was able to recreate the root user:



        DROP USER 'root'@'localhost';
        CREATE USER 'root'@'localhost' IDENTIFIED BY '<newpassword>';
        GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
        FLUSH PRIVILEGES;


        ... and finally all was right with the world again!



        I hope that helps a desperate soul out there...






        share|improve this answer




























          up vote
          0
          down vote















          1. Stop the MySQL Server.



            sudo /etc/init.d/mysql stop



          2. Start the mysqld configuration.



            sudo mysqld --skip-grant-tables &



          3. Login to MySQL as root.



            mysql -u root mysql



          4. Replace YOURNEWPASSWORD with your new password!



            UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;







          share|improve this answer






























            up vote
            0
            down vote














            1. sudo /etc/init.d/mysql stop

            2. sudo mkdir /var/run/mysqld/

            3. sudo chown mysql /var/run/mysqld/

            4. sudo mysqld_safe --skip-grant-tables &

            5. sudo mysql -u root

            6. use mysql;

            7. update user set authentication_string=PASSWORD("New_Passwore_Here") where User='root';

            8. flush privileges;

            9. exit;

            10. sudo /etc/init.d/mysql stop

            11. sudo /etc/init.d/mysql start






            share|improve this answer























            • Hello and welcome to AU. Your answer might be correct but should be documented: it is not recommended to just give an instruction list. In this case, I do not see a problem but, in general, if a user mistypes something, it could lead to unwanted results. You also use 'sudo' even when it is not necessary (sudo mysql...) which is potentially dangerous.
              – Marc Vanhoomissen
              May 14 at 12:02











            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',
            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%2f89895%2fwhich-is-the-easiest-way-to-reset-the-mysql-root-password%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








            up vote
            5
            down vote













            There's also an administrative user equivalent to root: debian-sys-maint. You can use this account to reset root's password. You can find its password in /etc/mysql/debian.cnf






            share|improve this answer

























              up vote
              5
              down vote













              There's also an administrative user equivalent to root: debian-sys-maint. You can use this account to reset root's password. You can find its password in /etc/mysql/debian.cnf






              share|improve this answer























                up vote
                5
                down vote










                up vote
                5
                down vote









                There's also an administrative user equivalent to root: debian-sys-maint. You can use this account to reset root's password. You can find its password in /etc/mysql/debian.cnf






                share|improve this answer












                There's also an administrative user equivalent to root: debian-sys-maint. You can use this account to reset root's password. You can find its password in /etc/mysql/debian.cnf







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 23 '11 at 6:18









                tumbleweed

                7,0981734




                7,0981734
























                    up vote
                    4
                    down vote













                    You could create a sql file say /root/mysql.reset.sql with the content:



                    UPDATE mysql.user SET Password=PASSWORD('yourpassword') WHERE User='root';
                    FLUSH PRIVILEGES;


                    And just call:



                    mysqld_safe --init-file=/root/mysql.reset.sql


                    Will be very helpful if you are in a habit of forgetting passwords often.






                    share|improve this answer



























                      up vote
                      4
                      down vote













                      You could create a sql file say /root/mysql.reset.sql with the content:



                      UPDATE mysql.user SET Password=PASSWORD('yourpassword') WHERE User='root';
                      FLUSH PRIVILEGES;


                      And just call:



                      mysqld_safe --init-file=/root/mysql.reset.sql


                      Will be very helpful if you are in a habit of forgetting passwords often.






                      share|improve this answer

























                        up vote
                        4
                        down vote










                        up vote
                        4
                        down vote









                        You could create a sql file say /root/mysql.reset.sql with the content:



                        UPDATE mysql.user SET Password=PASSWORD('yourpassword') WHERE User='root';
                        FLUSH PRIVILEGES;


                        And just call:



                        mysqld_safe --init-file=/root/mysql.reset.sql


                        Will be very helpful if you are in a habit of forgetting passwords often.






                        share|improve this answer














                        You could create a sql file say /root/mysql.reset.sql with the content:



                        UPDATE mysql.user SET Password=PASSWORD('yourpassword') WHERE User='root';
                        FLUSH PRIVILEGES;


                        And just call:



                        mysqld_safe --init-file=/root/mysql.reset.sql


                        Will be very helpful if you are in a habit of forgetting passwords often.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Oct 5 '15 at 15:23









                        snoop

                        2,86762650




                        2,86762650










                        answered Dec 23 '11 at 6:29









                        tamilsweet

                        1413




                        1413






















                            up vote
                            1
                            down vote













                            sudo dpkg-reconfigure mysql-server-5.5


                            you can use tab complete after mysql-server- if you're using a different version of mysql.






                            share|improve this answer

























                              up vote
                              1
                              down vote













                              sudo dpkg-reconfigure mysql-server-5.5


                              you can use tab complete after mysql-server- if you're using a different version of mysql.






                              share|improve this answer























                                up vote
                                1
                                down vote










                                up vote
                                1
                                down vote









                                sudo dpkg-reconfigure mysql-server-5.5


                                you can use tab complete after mysql-server- if you're using a different version of mysql.






                                share|improve this answer












                                sudo dpkg-reconfigure mysql-server-5.5


                                you can use tab complete after mysql-server- if you're using a different version of mysql.







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jun 10 '12 at 16:54









                                Colin Pickard

                                123113




                                123113






















                                    up vote
                                    1
                                    down vote













                                    tumbleweed's answer was the only one that helped me. I was dealing with what could possibly have been a corrupted root user and none of the standard methods resolved the issue of not being able to log in as root.



                                    Using the debian-sys-maint user, I was able to finally log into MySQL with escalated privileges and even then resetting the root password did not work.



                                    However, I was able to recreate the root user:



                                    DROP USER 'root'@'localhost';
                                    CREATE USER 'root'@'localhost' IDENTIFIED BY '<newpassword>';
                                    GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
                                    FLUSH PRIVILEGES;


                                    ... and finally all was right with the world again!



                                    I hope that helps a desperate soul out there...






                                    share|improve this answer

























                                      up vote
                                      1
                                      down vote













                                      tumbleweed's answer was the only one that helped me. I was dealing with what could possibly have been a corrupted root user and none of the standard methods resolved the issue of not being able to log in as root.



                                      Using the debian-sys-maint user, I was able to finally log into MySQL with escalated privileges and even then resetting the root password did not work.



                                      However, I was able to recreate the root user:



                                      DROP USER 'root'@'localhost';
                                      CREATE USER 'root'@'localhost' IDENTIFIED BY '<newpassword>';
                                      GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
                                      FLUSH PRIVILEGES;


                                      ... and finally all was right with the world again!



                                      I hope that helps a desperate soul out there...






                                      share|improve this answer























                                        up vote
                                        1
                                        down vote










                                        up vote
                                        1
                                        down vote









                                        tumbleweed's answer was the only one that helped me. I was dealing with what could possibly have been a corrupted root user and none of the standard methods resolved the issue of not being able to log in as root.



                                        Using the debian-sys-maint user, I was able to finally log into MySQL with escalated privileges and even then resetting the root password did not work.



                                        However, I was able to recreate the root user:



                                        DROP USER 'root'@'localhost';
                                        CREATE USER 'root'@'localhost' IDENTIFIED BY '<newpassword>';
                                        GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
                                        FLUSH PRIVILEGES;


                                        ... and finally all was right with the world again!



                                        I hope that helps a desperate soul out there...






                                        share|improve this answer












                                        tumbleweed's answer was the only one that helped me. I was dealing with what could possibly have been a corrupted root user and none of the standard methods resolved the issue of not being able to log in as root.



                                        Using the debian-sys-maint user, I was able to finally log into MySQL with escalated privileges and even then resetting the root password did not work.



                                        However, I was able to recreate the root user:



                                        DROP USER 'root'@'localhost';
                                        CREATE USER 'root'@'localhost' IDENTIFIED BY '<newpassword>';
                                        GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
                                        FLUSH PRIVILEGES;


                                        ... and finally all was right with the world again!



                                        I hope that helps a desperate soul out there...







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Feb 9 '17 at 10:21









                                        gopherIT

                                        112




                                        112






















                                            up vote
                                            0
                                            down vote















                                            1. Stop the MySQL Server.



                                              sudo /etc/init.d/mysql stop



                                            2. Start the mysqld configuration.



                                              sudo mysqld --skip-grant-tables &



                                            3. Login to MySQL as root.



                                              mysql -u root mysql



                                            4. Replace YOURNEWPASSWORD with your new password!



                                              UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;







                                            share|improve this answer



























                                              up vote
                                              0
                                              down vote















                                              1. Stop the MySQL Server.



                                                sudo /etc/init.d/mysql stop



                                              2. Start the mysqld configuration.



                                                sudo mysqld --skip-grant-tables &



                                              3. Login to MySQL as root.



                                                mysql -u root mysql



                                              4. Replace YOURNEWPASSWORD with your new password!



                                                UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;







                                              share|improve this answer

























                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote











                                                1. Stop the MySQL Server.



                                                  sudo /etc/init.d/mysql stop



                                                2. Start the mysqld configuration.



                                                  sudo mysqld --skip-grant-tables &



                                                3. Login to MySQL as root.



                                                  mysql -u root mysql



                                                4. Replace YOURNEWPASSWORD with your new password!



                                                  UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;







                                                share|improve this answer
















                                                1. Stop the MySQL Server.



                                                  sudo /etc/init.d/mysql stop



                                                2. Start the mysqld configuration.



                                                  sudo mysqld --skip-grant-tables &



                                                3. Login to MySQL as root.



                                                  mysql -u root mysql



                                                4. Replace YOURNEWPASSWORD with your new password!



                                                  UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;








                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Feb 9 '17 at 11:30









                                                Zanna

                                                49.2k13123234




                                                49.2k13123234










                                                answered Feb 9 '17 at 10:45









                                                Chetan Rathod

                                                1




                                                1






















                                                    up vote
                                                    0
                                                    down vote














                                                    1. sudo /etc/init.d/mysql stop

                                                    2. sudo mkdir /var/run/mysqld/

                                                    3. sudo chown mysql /var/run/mysqld/

                                                    4. sudo mysqld_safe --skip-grant-tables &

                                                    5. sudo mysql -u root

                                                    6. use mysql;

                                                    7. update user set authentication_string=PASSWORD("New_Passwore_Here") where User='root';

                                                    8. flush privileges;

                                                    9. exit;

                                                    10. sudo /etc/init.d/mysql stop

                                                    11. sudo /etc/init.d/mysql start






                                                    share|improve this answer























                                                    • Hello and welcome to AU. Your answer might be correct but should be documented: it is not recommended to just give an instruction list. In this case, I do not see a problem but, in general, if a user mistypes something, it could lead to unwanted results. You also use 'sudo' even when it is not necessary (sudo mysql...) which is potentially dangerous.
                                                      – Marc Vanhoomissen
                                                      May 14 at 12:02















                                                    up vote
                                                    0
                                                    down vote














                                                    1. sudo /etc/init.d/mysql stop

                                                    2. sudo mkdir /var/run/mysqld/

                                                    3. sudo chown mysql /var/run/mysqld/

                                                    4. sudo mysqld_safe --skip-grant-tables &

                                                    5. sudo mysql -u root

                                                    6. use mysql;

                                                    7. update user set authentication_string=PASSWORD("New_Passwore_Here") where User='root';

                                                    8. flush privileges;

                                                    9. exit;

                                                    10. sudo /etc/init.d/mysql stop

                                                    11. sudo /etc/init.d/mysql start






                                                    share|improve this answer























                                                    • Hello and welcome to AU. Your answer might be correct but should be documented: it is not recommended to just give an instruction list. In this case, I do not see a problem but, in general, if a user mistypes something, it could lead to unwanted results. You also use 'sudo' even when it is not necessary (sudo mysql...) which is potentially dangerous.
                                                      – Marc Vanhoomissen
                                                      May 14 at 12:02













                                                    up vote
                                                    0
                                                    down vote










                                                    up vote
                                                    0
                                                    down vote










                                                    1. sudo /etc/init.d/mysql stop

                                                    2. sudo mkdir /var/run/mysqld/

                                                    3. sudo chown mysql /var/run/mysqld/

                                                    4. sudo mysqld_safe --skip-grant-tables &

                                                    5. sudo mysql -u root

                                                    6. use mysql;

                                                    7. update user set authentication_string=PASSWORD("New_Passwore_Here") where User='root';

                                                    8. flush privileges;

                                                    9. exit;

                                                    10. sudo /etc/init.d/mysql stop

                                                    11. sudo /etc/init.d/mysql start






                                                    share|improve this answer















                                                    1. sudo /etc/init.d/mysql stop

                                                    2. sudo mkdir /var/run/mysqld/

                                                    3. sudo chown mysql /var/run/mysqld/

                                                    4. sudo mysqld_safe --skip-grant-tables &

                                                    5. sudo mysql -u root

                                                    6. use mysql;

                                                    7. update user set authentication_string=PASSWORD("New_Passwore_Here") where User='root';

                                                    8. flush privileges;

                                                    9. exit;

                                                    10. sudo /etc/init.d/mysql stop

                                                    11. sudo /etc/init.d/mysql start







                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited May 14 at 13:08









                                                    derHugo

                                                    2,25721428




                                                    2,25721428










                                                    answered May 14 at 11:47









                                                    samson mwanzia

                                                    1




                                                    1












                                                    • Hello and welcome to AU. Your answer might be correct but should be documented: it is not recommended to just give an instruction list. In this case, I do not see a problem but, in general, if a user mistypes something, it could lead to unwanted results. You also use 'sudo' even when it is not necessary (sudo mysql...) which is potentially dangerous.
                                                      – Marc Vanhoomissen
                                                      May 14 at 12:02


















                                                    • Hello and welcome to AU. Your answer might be correct but should be documented: it is not recommended to just give an instruction list. In this case, I do not see a problem but, in general, if a user mistypes something, it could lead to unwanted results. You also use 'sudo' even when it is not necessary (sudo mysql...) which is potentially dangerous.
                                                      – Marc Vanhoomissen
                                                      May 14 at 12:02
















                                                    Hello and welcome to AU. Your answer might be correct but should be documented: it is not recommended to just give an instruction list. In this case, I do not see a problem but, in general, if a user mistypes something, it could lead to unwanted results. You also use 'sudo' even when it is not necessary (sudo mysql...) which is potentially dangerous.
                                                    – Marc Vanhoomissen
                                                    May 14 at 12:02




                                                    Hello and welcome to AU. Your answer might be correct but should be documented: it is not recommended to just give an instruction list. In this case, I do not see a problem but, in general, if a user mistypes something, it could lead to unwanted results. You also use 'sudo' even when it is not necessary (sudo mysql...) which is potentially dangerous.
                                                    – Marc Vanhoomissen
                                                    May 14 at 12:02


















                                                    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.





                                                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                    Please pay close attention to the following guidance:


                                                    • 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%2f89895%2fwhich-is-the-easiest-way-to-reset-the-mysql-root-password%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

                                                    Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                                                    ComboBox Display Member on multiple fields

                                                    Is it possible to collect Nectar points via Trainline?