How to reset or change the MySQL root password?











up vote
120
down vote

favorite
63












How do I change the MySQL root password and username in ubuntu server? Do I need to stop the mysql service before setting any changes?



I have a phpmyadmin setup as well, will phpmyadmin get updated automatically?










share|improve this question
























  • If you don't need the data you can "reset" the password by removing mysql in its entirety: stackoverflow.com/questions/10853004/… then installing it again (it will prompt you for the "new" root password) FWIW :)
    – rogerdpack
    Jan 12 at 22:33










  • Do you know the MySQL root password?
    – Franck Dernoncourt
    Jan 22 at 22:29






  • 1




    in mysql-server-5.7 these methods dont work. use 'sudo' without password as mentioned in askubuntu.com/a/848504
    – Pragalathan M
    May 13 at 14:37















up vote
120
down vote

favorite
63












How do I change the MySQL root password and username in ubuntu server? Do I need to stop the mysql service before setting any changes?



I have a phpmyadmin setup as well, will phpmyadmin get updated automatically?










share|improve this question
























  • If you don't need the data you can "reset" the password by removing mysql in its entirety: stackoverflow.com/questions/10853004/… then installing it again (it will prompt you for the "new" root password) FWIW :)
    – rogerdpack
    Jan 12 at 22:33










  • Do you know the MySQL root password?
    – Franck Dernoncourt
    Jan 22 at 22:29






  • 1




    in mysql-server-5.7 these methods dont work. use 'sudo' without password as mentioned in askubuntu.com/a/848504
    – Pragalathan M
    May 13 at 14:37













up vote
120
down vote

favorite
63









up vote
120
down vote

favorite
63






63





How do I change the MySQL root password and username in ubuntu server? Do I need to stop the mysql service before setting any changes?



I have a phpmyadmin setup as well, will phpmyadmin get updated automatically?










share|improve this question















How do I change the MySQL root password and username in ubuntu server? Do I need to stop the mysql service before setting any changes?



I have a phpmyadmin setup as well, will phpmyadmin get updated automatically?







mysql ubuntu phpmyadmin






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 9 '14 at 7:42









Doomsday

2,0671727




2,0671727










asked May 15 '13 at 3:47









asm234

7373915




7373915












  • If you don't need the data you can "reset" the password by removing mysql in its entirety: stackoverflow.com/questions/10853004/… then installing it again (it will prompt you for the "new" root password) FWIW :)
    – rogerdpack
    Jan 12 at 22:33










  • Do you know the MySQL root password?
    – Franck Dernoncourt
    Jan 22 at 22:29






  • 1




    in mysql-server-5.7 these methods dont work. use 'sudo' without password as mentioned in askubuntu.com/a/848504
    – Pragalathan M
    May 13 at 14:37


















  • If you don't need the data you can "reset" the password by removing mysql in its entirety: stackoverflow.com/questions/10853004/… then installing it again (it will prompt you for the "new" root password) FWIW :)
    – rogerdpack
    Jan 12 at 22:33










  • Do you know the MySQL root password?
    – Franck Dernoncourt
    Jan 22 at 22:29






  • 1




    in mysql-server-5.7 these methods dont work. use 'sudo' without password as mentioned in askubuntu.com/a/848504
    – Pragalathan M
    May 13 at 14:37
















If you don't need the data you can "reset" the password by removing mysql in its entirety: stackoverflow.com/questions/10853004/… then installing it again (it will prompt you for the "new" root password) FWIW :)
– rogerdpack
Jan 12 at 22:33




If you don't need the data you can "reset" the password by removing mysql in its entirety: stackoverflow.com/questions/10853004/… then installing it again (it will prompt you for the "new" root password) FWIW :)
– rogerdpack
Jan 12 at 22:33












Do you know the MySQL root password?
– Franck Dernoncourt
Jan 22 at 22:29




Do you know the MySQL root password?
– Franck Dernoncourt
Jan 22 at 22:29




1




1




in mysql-server-5.7 these methods dont work. use 'sudo' without password as mentioned in askubuntu.com/a/848504
– Pragalathan M
May 13 at 14:37




in mysql-server-5.7 these methods dont work. use 'sudo' without password as mentioned in askubuntu.com/a/848504
– Pragalathan M
May 13 at 14:37












26 Answers
26






active

oldest

votes

















up vote
138
down vote



accepted










Set / change / reset the MySQL root password on Ubuntu Linux. Enter the following lines in your terminal.




  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
    mysql.user
    SET
    Password = PASSWORD('YOURNEWPASSWORD')
    WHERE
    User = 'root';
    FLUSH PRIVILEGES;
    exit;




Note: on some versions, if password column doesn't exist, you may want to try:
UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';




Note: This method is not regarded as the most secure way of resetting the password, however, it works.



References:




  1. Set / Change / Reset the MySQL root password on Ubuntu Linux

  2. How to Reset the Root Password






share|improve this answer



















  • 12




    Of course, after this point you'll need to kill the temporary, password-less server process that you started in step 2. maybe use sudo killall -9 mysqld? and then sudo service mysql start to restart the normal daemon...
    – Lambart
    Dec 8 '13 at 1:39






  • 7




    The method in this answer is only needed for resetting a MySQL root password that you don't know [source]. If you know it, the SET PASSWORD MySQL instruction is for you.
    – tanius
    Mar 6 '14 at 17:51








  • 10




    It doesn't work with me!
    – moderns
    Jul 14 '14 at 17:44






  • 32




    i followed till 3rd step and i get Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when i login thru root
    – Sushivam
    Nov 2 '16 at 11:24






  • 4




    in some cases, you also need to run mkdir /var/run/mysqld and chown mysql: /var/run/mysqld between steps 1 and 2
    – Neville Nazerane
    Feb 2 at 2:38


















up vote
84
down vote













The official and easy way to reset the root password on an ubuntu server...



If you are on 16.04, 14.04, 12.04:



sudo dpkg-reconfigure mysql-server-5.5


If you are on 10.04:



sudo dpkg-reconfigure mysql-server-5.1


If you are not sure which mysql-server version is installed you can try:



dpkg --get-selections | grep mysql-server


Updated notes for mysql-server-5.7



Note that if you are using mysql-server-5.7 you can not use the easier dpkg-reconfigure method shown above.



If you know the password, login and run this:



UPDATE mysql.user SET authentication_string=PASSWORD('my-new-password') WHERE USER='root';
FLUSH PRIVILEGES;


Alternatively, you can use the following:



sudo mysql_secure_installation


This will ask you a series of questions about securing your installation (highly recommended), including if you want to provide a new root password.



If you do NOT know the root password, refer to this Ubuntu-centric write up on the process.



See for more info:



https://help.ubuntu.com/16.04/serverguide/mysql.html
https://help.ubuntu.com/14.04/serverguide/mysql.html






share|improve this answer



















  • 3




    Works even when you lost the original MySQL root password – nice.
    – tanius
    May 2 '14 at 12:29






  • 3




    Works with Ver 14.14 Distrib 5.5.38, for debian-linux-gnu
    – justinpage
    Sep 14 '14 at 1:56










  • This worked for me on 5.5.40-0ubuntu0.14.04.1
    – ken koehler
    Jan 15 '15 at 19:14






  • 19




    Doesn't seem to work with 5.7 on newer ubuntu
    – fuzzyTew
    Dec 26 '16 at 2:15






  • 2




    sudo dpkg-reconfigure mysql-server-5.7 not working for Ubuntu 18.04 for reset root password. Any other alternate?
    – Jagdeep Singh
    May 21 at 6:25




















up vote
68
down vote













I am sharing the step by step final solution to reset a MySQL password in Linux
Ubuntu.



Reference taken from blog (dbrnd.com)



Step 1:
Stop MySQL Service.



sudo stop mysql


Step 2:
Kill all running mysqld.



sudo killall -9 mysqld


Step 3:
Starting mysqld in Safe mode.



sudo mysqld_safe --skip-grant-tables --skip-networking &


Step 4:
Start mysql client



mysql -u root


Step 5:
After successful login, please execute this command to change any password.



FLUSH PRIVILEGES;


Step 6:
You can update mysql root password .



UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';


Note: On MySQL 5.7, column Password is called authentication_string.



Step 7:
Please execute this command.



FLUSH PRIVILEGES;





share|improve this answer



















  • 3




    This actually worked for me, not the accepted answer, give it a try!
    – Santiago Martí Olbrich
    Oct 20 '15 at 14:49










  • Indeed. Also, it is closer to the official documentation. In case you run into this: "ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded”, take a look at stackoverflow.com/questions/37879448/…
    – Wtower
    Aug 22 '16 at 9:36










  • I also had to change mysql.user.plugin from 'auth_socket' to 'mysql_native_password' for my root user with host of 'localhost'.
    – Brandon
    May 17 '17 at 2:16






  • 1




    I had to use "sudo /etc/init.d/mysql stop" to stop the service and "UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root';" to update the password
    – L Bahr
    Aug 15 '17 at 1:55






  • 1




    authenticated _string helped
    – Faiyaz Md Abdul
    Nov 24 '17 at 17:49


















up vote
65
down vote













The only method that worked for me is the one described here (I am running ubuntu 14.04). For the sake of clarity, these are the steps I followed:




  1. sudo vim /etc/mysql/my.cnf


  2. Add the following lines at the end:



    [mysqld]

    skip-grant-tables


  3. sudo service mysql restart


  4. mysql -u root


  5. use mysql


  6. select * from mysql.user where user = 'root'; - Look at the top to determine whether the password column is called
    password or authentication_string


  7. UPDATE mysql.user set *password_field from above* = PASSWORD('your_new_password') where user = 'root' and host = 'localhost'; - Use the proper password column from above


  8. FLUSH PRIVILEGES;


  9. exit


  10. sudo vim /etc/mysql/my.cnf


  11. Remove the lines added in step 2 if you want to keep your security standards.


  12. sudo service mysql restart



For reference : https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html






share|improve this answer



















  • 5




    Finally, this worked for me! I'm running MySQL 5.7.18 on Ubuntu 16.04. I tried dpkg-reconfigure, Anvesh's answer, Christian Mark's answer, and even the instructions on MySQL's help page.
    – mbuc91
    May 11 '17 at 5:15






  • 7




    I had to run UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root'; instead for line 5.
    – mbuc91
    May 11 '17 at 5:21










  • The only solution that worked for me. I have Ubuntu 17.04 and mysql 5.7
    – Mohamed
    Nov 20 '17 at 1:52










  • In point 6 you have to add user should be this way select * from mysql.user where user = 'root';
    – user615274
    May 17 at 2:50










  • Sad this does not work for me mysql 5.7.22 ubuntu 18.04
    – user615274
    May 17 at 2:55


















up vote
33
down vote













Change the MySQL root password.



This method exposes the password to the command-line history, these commands should be run as root.





  1. Login through mysql command line tool:



    mysql -uroot -poldpassword



  2. Run this command:



    SET PASSWORD FOR root@'localhost' = PASSWORD('newpassword');



or





  1. Run this command, which sets a password for the current user ('root' for this case) :




    SET PASSWORD = PASSWORD('newpassword');









share|improve this answer






























    up vote
    27
    down vote













    What worked for me (Ubuntu 16.04, mysql 5.7):



    Stop MySQL



    sudo service mysql stop


    Make MySQL service directory.



    sudo mkdir /var/run/mysqld


    Give MySQL user permission to write to the service directory.



    sudo chown mysql: /var/run/mysqld


    Start MySQL manually, without permission checks or networking.



    sudo mysqld_safe --skip-grant-tables --skip-networking &


    On another console, log in without a password.



    mysql -uroot mysql


    Then:



    UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
    EXIT;


    Turn off MySQL.



    sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


    Start the MySQL service normally.



    sudo service mysql start





    share|improve this answer





















    • The other ways did not work for me but this one (thanks!), or you can also go here rricketts.com/reset-root-password-mysql-5-7-ubuntu-16-04-lts
      – Dung
      Dec 7 '17 at 17:25








    • 5




      Very useful ! In my specific case (Ubuntu 18.04 LTS), I had to replace the host '%' to 'localhost'
      – FredericK
      May 7 at 13:16


















    up vote
    12
    down vote













    If you would like to change the MySQL root password, in a terminal enter:



    sudo dpkg-reconfigure mysql-server-5.5



    The MySQL daemon will be stopped, and you will be prompted to enter a new password.






    share|improve this answer

















    • 1




      This is a much better way to do it. I was unable to run the previous commands because of some mysql error...
      – Andy
      Jan 28 '16 at 3:46










    • sudo dpkg-reconfigure mysql-server-5.7 on ubuntu 16.04
      – Nick Barrett
      Feb 28 '17 at 6:42






    • 1




      I ran sudo dpkg-reconfigure mysql-server-5.7 on Ubuntu 16.04, it didn't prompt to enter a new password.
      – Franck Dernoncourt
      Jan 22 at 22:32










    • If it says mysql-server is broken or not fully installed, one can use sudo apt purge mysql* and sudo apt install mysql-server
      – Pavel
      Oct 22 at 7:30


















    up vote
    11
    down vote













    I faced problems with ubuntu 18.04 and mysql 5.7, this is the solution



    MYSQL-SERVER >= 5.7



    sudo mysql -uroot -p
    USE mysql;
    UPDATE user SET authentication_string=PASSWORD('YOUR_PASSWORD') WHERE User='root';
    UPDATE user SET plugin="mysql_native_password";
    FLUSH PRIVILEGES;
    quit;


    MYSQL-SERVER < 5.7



    sudo mysql -uroot -p
    USE mysql;
    UPDATE user SET password=PASSWORD('YOUR_PASSWORD') WHERE User='root';
    UPDATE user SET plugin="mysql_native_password";
    FLUSH PRIVILEGES;
    quit;





    share|improve this answer

















    • 1




      Thanks, I'm also running Ubuntu 18.04 here and the MYSQL-SERVER >= 5.7 version was the only thing that actually solved the problem
      – Miguelgraz
      Jul 4 at 12:41






    • 1




      Good thing it was helpful, share it with anyone who has the same problem.
      – Jerfeson Guerreiro
      Jul 5 at 0:03










    • So para constar acho que o root do mysql so é acessado pelo sudo. Pelo menos foi o que funcionou pra mim.
      – Ismael Junior
      Jul 19 at 18:52


















    up vote
    9
    down vote













    This works like charm I did it for Ubuntu 16.04.
    Full credit to below link as I got it from there.
    [https://coderwall.com/p/j9btlg/reset-the-mysql-5-7-root-password-in-ubuntu-16-04-lts][1]



    Stop MySQL



    sudo service mysql stop


    Make MySQL service directory.
    sudo mkdir /var/run/mysqld



    Give MySQL user permission to write to the service directory.



    sudo chown mysql: /var/run/mysqld


    Start MySQL manually, without permission checks or networking.



    sudo mysqld_safe --skip-grant-tables --skip-networking &


    Log in without a password.



    mysql -uroot mysql


    Update the password for the root user.
    make sure at atleast root account gets updated by the below query.
    make some selection and check the existing values if you like



    UPDATE mysql.user SET 
    authentication_string=PASSWORD('YOURNEWPASSWORD'),
    plugin='mysql_native_password' WHERE User='root' AND Host='%';
    EXIT;


    Turn off MySQL.



    sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


    Start the MySQL service normally.



    sudo service mysql start





    share|improve this answer






























      up vote
      8
      down vote














      1. Stop MySQL
        sudo service mysql stop


      2. Make MySQL service directory.
        sudo mkdir /var/run/mysqld


      3. Give MySQL user permission to write to the service directory.
        sudo chown mysql: /var/run/mysqld


      4. Start MySQL manually, without permission checks or networking.
        sudo mysqld_safe --skip-grant-tables --skip-networking &



      5.Log in without a password.
      mysql -uroot mysql



      6.Update the password for the root user.



      UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
      EXIT;




      1. Turn off MySQL.
        sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


      2. Start the MySQL service normally.
        sudo service mysql start







      share|improve this answer





















      • Hi, this answer works for me, but I had to use another command: UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root'; without AND Host='%'. Thanks!
        – David Corral
        May 22 at 17:51


















      up vote
      7
      down vote













      This solution belongs to the previous version of MySQL.
      By logging in to MySQL using socket authentication, you can do it.



      sudo mysql -u root


      Then the following command could be run.



      ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';


      Details are available here .






      share|improve this answer

















      • 1




        I couldn't login as sudo mysql -u root but I was able to do it as sudo mysql and run the ALTER USER command.
        – itsols
        Oct 24 at 7:59






      • 1




        Life savior. Quick and clean.
        – Marcelo Agimóvel
        Nov 4 at 0:08


















      up vote
      6
      down vote













      Echoing rogerdpack's comment: if you don't know the MySQL root password and you don't care about MySQL data/settings, you can reinstall it and reset the root's password as follows:



      sudo apt-get remove --purge mysql-server mysql-client mysql-common
      sudo rm -rf /var/lib/mysql
      sudo apt-get install -y mysql-server mysql-client


      During the installation, you can choose the root's password:



      enter image description here






      share|improve this answer



















      • 1




        I wish I had started here instead of wasting an hour banging my head at trying to reset the password.
        – Eric Seastrand
        Sep 12 at 23:23


















      up vote
      3
      down vote













      If you know your current password, you don't have to stop mysql server.
      Open the ubuntu terminal.
      Login to mysql using:



      mysql - username -p


      Then type your password.
      This will take you into the mysql console.
      Inside the console, type:



      > ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';


      Then flush privileges using:



      > flush privileges;


      Then you are all done.






      share|improve this answer




























        up vote
        2
        down vote













        When you use MySQL's PASSWORD() on the system where you want to change the password, it can cause the password turn up in a MySQL log in cleartext [source]. Keeping them, their backups etc. as secure as the password sounds like nightmare to me, so I rather like to do it as follows:





        1. On your local machine, run this with your password:



           mysql -u someuser -p < <(echo "SELECT PASSWORD('mypass');")


          Note the space in front to prevent it from turning up in the bash history (for other distros than Ubuntu, this might work differently – source).




        2. On your server machine, execute the following command to change its MySQL root password (replace myhash with your password's hash as printed by the first command):



          mysql -u root -p < <(echo "SET PASSWORD FOR root@localhost = 'myhash';")


        3. Optionally, let's be a bit paranoid: On your local machine, clear your terminal screen with clear and purge your virtual terminal scrollback, to hide the cleartext password appearing in the command above.







        share|improve this answer






























          up vote
          2
          down vote













          To update the "root" Mysql user password you must have in mind that you will need of super user permissions for that. If you have super user privilegies, try the following commands:



          MySQL 5.7.6 and later



          sudo su
          service mysql stop
          mysql -u root
          ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
          q;
          exit
          mysql -u root -p MyNewPass


          MySQL 5.7.5 and earlier



          sudo su
          service mysql stop
          mysql -u root
          SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
          q;
          exit
          mysql -u root -p MyNewPass





          share|improve this answer




























            up vote
            1
            down vote













            Instead of resetting the password there is a work around on the local machine if you have setup phpmyadmin to connect without giving the password or username. Check this out by starting mysql, apache etc. I have xampp installed in my local machine. So starting the xampp will start all the necessary services. Now going to http://localhost/phpmyadmin shows me all the databases. This confirms that you have saved the username and passsword in the config file of phpmyadmin which can be found in the phpmyadmin install location. If you have xampp installed the phpmyadmin folder can be found in the root folder of xampp installation. Search for the word password in the config.inc.php file. There you will find the password and username.






            share|improve this answer




























              up vote
              1
              down vote













              You can easily change the mysql password if deployed on xampp through provided phpadmin gui.



              phpMyAdmin -> User Accounts -> Edit Privileges (Select the intended user) -> Change Password (Tab)





              share|improve this answer




























                up vote
                1
                down vote













                You can use this command :



                UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';



                after that pleas use flush
                FLUSH PRIVILEGES;






                share|improve this answer




























                  up vote
                  1
                  down vote













                  for mysql 5.6 this command works and you can set password through the wizard:



                  sudo dpkg-reconfigure mysql-server-5.6





                  share|improve this answer





















                  • I tried but its not working.. I am getting this bellow error.. could you please help? This installation of MySQL is already upgraded to 5.7.21, use --force if you still need to run mysql_upgrade
                    – Vijaysinh Parmar
                    Mar 23 at 7:30


















                  up vote
                  1
                  down vote













                  You don't need all this. Simply log in:



                  mysql -u root -p



                  Then change the current user's password as the mysql> prompt:



                  mysql> set password=password('the_new_password');
                  mysql> flush privileges;





                  share|improve this answer




























                    up vote
                    1
                    down vote













                    You can try these some steps to reset mysql 5.7 root password :



                    Stop Mysql Service 1st



                    sudo /etc/init.d/mysql stop 


                    Login as root without password
                    sudo mysqld_safe --skip-grant-tables &



                    After login mysql terminal you should need execute commands more:



                    use mysql;




                    UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root';


                    flush privileges;


                    sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                    After you restart your mysql server
                    If you still facing error you must visit :
                    Reset MySQL 5.7 root password Ubuntu 16.04






                    share|improve this answer






























                      up vote
                      1
                      down vote













                      This is the solution for me. I work at Ubuntu 18.04:
                      https://stackoverflow.com/a/46076838/2400373



                      But is important this change in the last step:



                      UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost'; 





                      share|improve this answer




























                        up vote
                        0
                        down vote













                        when changing/resetting the MySQL password the following commands listed above did not help. I found that going into the terminal and using these commands is pointless. instead use the command sudo stop everything. DELETE SYSTEM 32 for windows if that helps.






                        share|improve this answer

















                        • 1




                          The question is about ubuntu OS not windows. What do you mean by DELETE SYSTEM 32 for windows?
                          – EhsanT
                          Jan 14 '17 at 2:13


















                        up vote
                        0
                        down vote













                        To reset or change the password enter sudo dpkg-reconfigure mysql-server-X.X (X.X is mysql version you have installed i.e. 5.6, 5.7) and then you will prompt a screen where you have to set the new password and then in next step confirm the password and just wait for a moment. That's it.






                        share|improve this answer




























                          up vote
                          0
                          down vote













                          I had to go this route on Ubuntu 16.04.1 LTS. It is somewhat of a mix of some of the other answers above - but none of them helped. I spent an hour or more trying all other suggestions from MySql website to everything on SO, I finally got it working with:


                          Note: while it showed Enter password for user root, I didnt have the original password so I just entered the same password to be used as the new password.


                          Note: there was no /var/log/mysqld.log only /var/log/mysql/error.log



                          Also note this did not work for me:

                          sudo dpkg-reconfigure mysql-server-5.7



                          Nor did:

                          sudo dpkg-reconfigure --force mysql-server-5.5



                          Make MySQL service directory.

                          sudo mkdir /var/run/mysqld



                          Give MySQL user permission to write to the service directory.

                          sudo chown mysql: /var/run/mysqld



                          Then:




                          1. kill the current mysqld pid

                          2. run mysqld with sudo /usr/sbin/mysqld &


                          3. run /usr/bin/mysql_secure_installation


                            Output from mysql_secure_installation




                            root@myServer:~# /usr/bin/mysql_secure_installation



                            Securing the MySQL server deployment.



                            Enter password for user root:



                            VALIDATE PASSWORD PLUGIN can be used to test passwords
                            and improve security. It checks the strength of password
                            and allows the users to set only those passwords which are
                            secure enough. Would you like to setup VALIDATE PASSWORD plugin?



                            Press y|Y for Yes, any other key for No: no
                            Using existing password for root.
                            Change the password for root ? ((Press y|Y for Yes, any other key for No) : y



                            New password:



                            Re-enter new password:
                            By default, a MySQL installation has an anonymous user,
                            allowing anyone to log into MySQL without having to have
                            a user account created for them. This is intended only for
                            testing, and to make the installation go a bit smoother.
                            You should remove them before moving into a production
                            environment.



                            Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
                            Success.



                            Normally, root should only be allowed to connect from
                            'localhost'. This ensures that someone cannot guess at
                            the root password from the network.



                            Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
                            Success.



                            By default, MySQL comes with a database named 'test' that
                            anyone can access. This is also intended only for testing,
                            and should be removed before moving into a production
                            environment.



                            Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y




                            • Dropping test database...
                              Success.


                            • Removing privileges on test database...
                              Success.



                            Reloading the privilege tables will ensure that all changes
                            made so far will take effect immediately.



                            Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
                            Success.



                            All done!









                          share|improve this answer




























                            up vote
                            0
                            down vote













                            As mysql documentation on the password() function says:




                            This function was removed in MySQL 8.0.11.




                            This invalidates pretty much all existing answers for mysql v8.0.11 and newer.



                            Per mysql documentation the new generic way to reset the root password is as follows:




                            The preceding sections provide password-resetting instructions
                            specifically for Windows and Unix and Unix-like systems.
                            Alternatively, on any platform, you can reset the password using the
                            mysql client (but this approach is less secure):



                            Stop the MySQL server if necessary, then restart it with the
                            --skip-grant-tables option. This enables anyone to connect without a password and with all privileges, and disables account-management
                            statements such as ALTER USER and SET PASSWORD. Because this is
                            insecure, if the server is started with the --skip-grant-tables
                            option, it enables --skip-networking automatically to prevent remote
                            connections.



                            Connect to the MySQL server using the mysql client; no password is
                            necessary because the server was started with --skip-grant-tables:



                            shell> mysql


                            In the mysql client, tell the server to reload the grant tables so that account-management statements work:



                            mysql> FLUSH PRIVILEGES;


                            Then change the 'root'@'localhost' account password. Replace the password with the password that you want to use.
                            To change the password for a root account with a different host name
                            part, modify the instructions to use that host name.



                            mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';


                            You should now be able to connect to the MySQL server as root using the
                            new password. Stop the server and restart it normally (without the
                            --skip-grant-tables and --skip-networking options).







                            share|improve this answer





















                              Your Answer






                              StackExchange.ifUsing("editor", function () {
                              StackExchange.using("externalEditor", function () {
                              StackExchange.using("snippets", function () {
                              StackExchange.snippets.init();
                              });
                              });
                              }, "code-snippets");

                              StackExchange.ready(function() {
                              var channelOptions = {
                              tags: "".split(" "),
                              id: "1"
                              };
                              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%2fstackoverflow.com%2fquestions%2f16556497%2fhow-to-reset-or-change-the-mysql-root-password%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown

























                              26 Answers
                              26






                              active

                              oldest

                              votes








                              26 Answers
                              26






                              active

                              oldest

                              votes









                              active

                              oldest

                              votes






                              active

                              oldest

                              votes








                              up vote
                              138
                              down vote



                              accepted










                              Set / change / reset the MySQL root password on Ubuntu Linux. Enter the following lines in your terminal.




                              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
                                mysql.user
                                SET
                                Password = PASSWORD('YOURNEWPASSWORD')
                                WHERE
                                User = 'root';
                                FLUSH PRIVILEGES;
                                exit;




                              Note: on some versions, if password column doesn't exist, you may want to try:
                              UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';




                              Note: This method is not regarded as the most secure way of resetting the password, however, it works.



                              References:




                              1. Set / Change / Reset the MySQL root password on Ubuntu Linux

                              2. How to Reset the Root Password






                              share|improve this answer



















                              • 12




                                Of course, after this point you'll need to kill the temporary, password-less server process that you started in step 2. maybe use sudo killall -9 mysqld? and then sudo service mysql start to restart the normal daemon...
                                – Lambart
                                Dec 8 '13 at 1:39






                              • 7




                                The method in this answer is only needed for resetting a MySQL root password that you don't know [source]. If you know it, the SET PASSWORD MySQL instruction is for you.
                                – tanius
                                Mar 6 '14 at 17:51








                              • 10




                                It doesn't work with me!
                                – moderns
                                Jul 14 '14 at 17:44






                              • 32




                                i followed till 3rd step and i get Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when i login thru root
                                – Sushivam
                                Nov 2 '16 at 11:24






                              • 4




                                in some cases, you also need to run mkdir /var/run/mysqld and chown mysql: /var/run/mysqld between steps 1 and 2
                                – Neville Nazerane
                                Feb 2 at 2:38















                              up vote
                              138
                              down vote



                              accepted










                              Set / change / reset the MySQL root password on Ubuntu Linux. Enter the following lines in your terminal.




                              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
                                mysql.user
                                SET
                                Password = PASSWORD('YOURNEWPASSWORD')
                                WHERE
                                User = 'root';
                                FLUSH PRIVILEGES;
                                exit;




                              Note: on some versions, if password column doesn't exist, you may want to try:
                              UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';




                              Note: This method is not regarded as the most secure way of resetting the password, however, it works.



                              References:




                              1. Set / Change / Reset the MySQL root password on Ubuntu Linux

                              2. How to Reset the Root Password






                              share|improve this answer



















                              • 12




                                Of course, after this point you'll need to kill the temporary, password-less server process that you started in step 2. maybe use sudo killall -9 mysqld? and then sudo service mysql start to restart the normal daemon...
                                – Lambart
                                Dec 8 '13 at 1:39






                              • 7




                                The method in this answer is only needed for resetting a MySQL root password that you don't know [source]. If you know it, the SET PASSWORD MySQL instruction is for you.
                                – tanius
                                Mar 6 '14 at 17:51








                              • 10




                                It doesn't work with me!
                                – moderns
                                Jul 14 '14 at 17:44






                              • 32




                                i followed till 3rd step and i get Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when i login thru root
                                – Sushivam
                                Nov 2 '16 at 11:24






                              • 4




                                in some cases, you also need to run mkdir /var/run/mysqld and chown mysql: /var/run/mysqld between steps 1 and 2
                                – Neville Nazerane
                                Feb 2 at 2:38













                              up vote
                              138
                              down vote



                              accepted







                              up vote
                              138
                              down vote



                              accepted






                              Set / change / reset the MySQL root password on Ubuntu Linux. Enter the following lines in your terminal.




                              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
                                mysql.user
                                SET
                                Password = PASSWORD('YOURNEWPASSWORD')
                                WHERE
                                User = 'root';
                                FLUSH PRIVILEGES;
                                exit;




                              Note: on some versions, if password column doesn't exist, you may want to try:
                              UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';




                              Note: This method is not regarded as the most secure way of resetting the password, however, it works.



                              References:




                              1. Set / Change / Reset the MySQL root password on Ubuntu Linux

                              2. How to Reset the Root Password






                              share|improve this answer














                              Set / change / reset the MySQL root password on Ubuntu Linux. Enter the following lines in your terminal.




                              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
                                mysql.user
                                SET
                                Password = PASSWORD('YOURNEWPASSWORD')
                                WHERE
                                User = 'root';
                                FLUSH PRIVILEGES;
                                exit;




                              Note: on some versions, if password column doesn't exist, you may want to try:
                              UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';




                              Note: This method is not regarded as the most secure way of resetting the password, however, it works.



                              References:




                              1. Set / Change / Reset the MySQL root password on Ubuntu Linux

                              2. How to Reset the Root Password







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited May 17 at 3:09









                              Lemayzeur

                              5,1371833




                              5,1371833










                              answered May 15 '13 at 3:52









                              Christian Mark

                              5,256123374




                              5,256123374








                              • 12




                                Of course, after this point you'll need to kill the temporary, password-less server process that you started in step 2. maybe use sudo killall -9 mysqld? and then sudo service mysql start to restart the normal daemon...
                                – Lambart
                                Dec 8 '13 at 1:39






                              • 7




                                The method in this answer is only needed for resetting a MySQL root password that you don't know [source]. If you know it, the SET PASSWORD MySQL instruction is for you.
                                – tanius
                                Mar 6 '14 at 17:51








                              • 10




                                It doesn't work with me!
                                – moderns
                                Jul 14 '14 at 17:44






                              • 32




                                i followed till 3rd step and i get Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when i login thru root
                                – Sushivam
                                Nov 2 '16 at 11:24






                              • 4




                                in some cases, you also need to run mkdir /var/run/mysqld and chown mysql: /var/run/mysqld between steps 1 and 2
                                – Neville Nazerane
                                Feb 2 at 2:38














                              • 12




                                Of course, after this point you'll need to kill the temporary, password-less server process that you started in step 2. maybe use sudo killall -9 mysqld? and then sudo service mysql start to restart the normal daemon...
                                – Lambart
                                Dec 8 '13 at 1:39






                              • 7




                                The method in this answer is only needed for resetting a MySQL root password that you don't know [source]. If you know it, the SET PASSWORD MySQL instruction is for you.
                                – tanius
                                Mar 6 '14 at 17:51








                              • 10




                                It doesn't work with me!
                                – moderns
                                Jul 14 '14 at 17:44






                              • 32




                                i followed till 3rd step and i get Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when i login thru root
                                – Sushivam
                                Nov 2 '16 at 11:24






                              • 4




                                in some cases, you also need to run mkdir /var/run/mysqld and chown mysql: /var/run/mysqld between steps 1 and 2
                                – Neville Nazerane
                                Feb 2 at 2:38








                              12




                              12




                              Of course, after this point you'll need to kill the temporary, password-less server process that you started in step 2. maybe use sudo killall -9 mysqld? and then sudo service mysql start to restart the normal daemon...
                              – Lambart
                              Dec 8 '13 at 1:39




                              Of course, after this point you'll need to kill the temporary, password-less server process that you started in step 2. maybe use sudo killall -9 mysqld? and then sudo service mysql start to restart the normal daemon...
                              – Lambart
                              Dec 8 '13 at 1:39




                              7




                              7




                              The method in this answer is only needed for resetting a MySQL root password that you don't know [source]. If you know it, the SET PASSWORD MySQL instruction is for you.
                              – tanius
                              Mar 6 '14 at 17:51






                              The method in this answer is only needed for resetting a MySQL root password that you don't know [source]. If you know it, the SET PASSWORD MySQL instruction is for you.
                              – tanius
                              Mar 6 '14 at 17:51






                              10




                              10




                              It doesn't work with me!
                              – moderns
                              Jul 14 '14 at 17:44




                              It doesn't work with me!
                              – moderns
                              Jul 14 '14 at 17:44




                              32




                              32




                              i followed till 3rd step and i get Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when i login thru root
                              – Sushivam
                              Nov 2 '16 at 11:24




                              i followed till 3rd step and i get Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when i login thru root
                              – Sushivam
                              Nov 2 '16 at 11:24




                              4




                              4




                              in some cases, you also need to run mkdir /var/run/mysqld and chown mysql: /var/run/mysqld between steps 1 and 2
                              – Neville Nazerane
                              Feb 2 at 2:38




                              in some cases, you also need to run mkdir /var/run/mysqld and chown mysql: /var/run/mysqld between steps 1 and 2
                              – Neville Nazerane
                              Feb 2 at 2:38












                              up vote
                              84
                              down vote













                              The official and easy way to reset the root password on an ubuntu server...



                              If you are on 16.04, 14.04, 12.04:



                              sudo dpkg-reconfigure mysql-server-5.5


                              If you are on 10.04:



                              sudo dpkg-reconfigure mysql-server-5.1


                              If you are not sure which mysql-server version is installed you can try:



                              dpkg --get-selections | grep mysql-server


                              Updated notes for mysql-server-5.7



                              Note that if you are using mysql-server-5.7 you can not use the easier dpkg-reconfigure method shown above.



                              If you know the password, login and run this:



                              UPDATE mysql.user SET authentication_string=PASSWORD('my-new-password') WHERE USER='root';
                              FLUSH PRIVILEGES;


                              Alternatively, you can use the following:



                              sudo mysql_secure_installation


                              This will ask you a series of questions about securing your installation (highly recommended), including if you want to provide a new root password.



                              If you do NOT know the root password, refer to this Ubuntu-centric write up on the process.



                              See for more info:



                              https://help.ubuntu.com/16.04/serverguide/mysql.html
                              https://help.ubuntu.com/14.04/serverguide/mysql.html






                              share|improve this answer



















                              • 3




                                Works even when you lost the original MySQL root password – nice.
                                – tanius
                                May 2 '14 at 12:29






                              • 3




                                Works with Ver 14.14 Distrib 5.5.38, for debian-linux-gnu
                                – justinpage
                                Sep 14 '14 at 1:56










                              • This worked for me on 5.5.40-0ubuntu0.14.04.1
                                – ken koehler
                                Jan 15 '15 at 19:14






                              • 19




                                Doesn't seem to work with 5.7 on newer ubuntu
                                – fuzzyTew
                                Dec 26 '16 at 2:15






                              • 2




                                sudo dpkg-reconfigure mysql-server-5.7 not working for Ubuntu 18.04 for reset root password. Any other alternate?
                                – Jagdeep Singh
                                May 21 at 6:25

















                              up vote
                              84
                              down vote













                              The official and easy way to reset the root password on an ubuntu server...



                              If you are on 16.04, 14.04, 12.04:



                              sudo dpkg-reconfigure mysql-server-5.5


                              If you are on 10.04:



                              sudo dpkg-reconfigure mysql-server-5.1


                              If you are not sure which mysql-server version is installed you can try:



                              dpkg --get-selections | grep mysql-server


                              Updated notes for mysql-server-5.7



                              Note that if you are using mysql-server-5.7 you can not use the easier dpkg-reconfigure method shown above.



                              If you know the password, login and run this:



                              UPDATE mysql.user SET authentication_string=PASSWORD('my-new-password') WHERE USER='root';
                              FLUSH PRIVILEGES;


                              Alternatively, you can use the following:



                              sudo mysql_secure_installation


                              This will ask you a series of questions about securing your installation (highly recommended), including if you want to provide a new root password.



                              If you do NOT know the root password, refer to this Ubuntu-centric write up on the process.



                              See for more info:



                              https://help.ubuntu.com/16.04/serverguide/mysql.html
                              https://help.ubuntu.com/14.04/serverguide/mysql.html






                              share|improve this answer



















                              • 3




                                Works even when you lost the original MySQL root password – nice.
                                – tanius
                                May 2 '14 at 12:29






                              • 3




                                Works with Ver 14.14 Distrib 5.5.38, for debian-linux-gnu
                                – justinpage
                                Sep 14 '14 at 1:56










                              • This worked for me on 5.5.40-0ubuntu0.14.04.1
                                – ken koehler
                                Jan 15 '15 at 19:14






                              • 19




                                Doesn't seem to work with 5.7 on newer ubuntu
                                – fuzzyTew
                                Dec 26 '16 at 2:15






                              • 2




                                sudo dpkg-reconfigure mysql-server-5.7 not working for Ubuntu 18.04 for reset root password. Any other alternate?
                                – Jagdeep Singh
                                May 21 at 6:25















                              up vote
                              84
                              down vote










                              up vote
                              84
                              down vote









                              The official and easy way to reset the root password on an ubuntu server...



                              If you are on 16.04, 14.04, 12.04:



                              sudo dpkg-reconfigure mysql-server-5.5


                              If you are on 10.04:



                              sudo dpkg-reconfigure mysql-server-5.1


                              If you are not sure which mysql-server version is installed you can try:



                              dpkg --get-selections | grep mysql-server


                              Updated notes for mysql-server-5.7



                              Note that if you are using mysql-server-5.7 you can not use the easier dpkg-reconfigure method shown above.



                              If you know the password, login and run this:



                              UPDATE mysql.user SET authentication_string=PASSWORD('my-new-password') WHERE USER='root';
                              FLUSH PRIVILEGES;


                              Alternatively, you can use the following:



                              sudo mysql_secure_installation


                              This will ask you a series of questions about securing your installation (highly recommended), including if you want to provide a new root password.



                              If you do NOT know the root password, refer to this Ubuntu-centric write up on the process.



                              See for more info:



                              https://help.ubuntu.com/16.04/serverguide/mysql.html
                              https://help.ubuntu.com/14.04/serverguide/mysql.html






                              share|improve this answer














                              The official and easy way to reset the root password on an ubuntu server...



                              If you are on 16.04, 14.04, 12.04:



                              sudo dpkg-reconfigure mysql-server-5.5


                              If you are on 10.04:



                              sudo dpkg-reconfigure mysql-server-5.1


                              If you are not sure which mysql-server version is installed you can try:



                              dpkg --get-selections | grep mysql-server


                              Updated notes for mysql-server-5.7



                              Note that if you are using mysql-server-5.7 you can not use the easier dpkg-reconfigure method shown above.



                              If you know the password, login and run this:



                              UPDATE mysql.user SET authentication_string=PASSWORD('my-new-password') WHERE USER='root';
                              FLUSH PRIVILEGES;


                              Alternatively, you can use the following:



                              sudo mysql_secure_installation


                              This will ask you a series of questions about securing your installation (highly recommended), including if you want to provide a new root password.



                              If you do NOT know the root password, refer to this Ubuntu-centric write up on the process.



                              See for more info:



                              https://help.ubuntu.com/16.04/serverguide/mysql.html
                              https://help.ubuntu.com/14.04/serverguide/mysql.html







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Dec 6 '17 at 5:00

























                              answered Mar 27 '14 at 3:57









                              user12345

                              1,59911617




                              1,59911617








                              • 3




                                Works even when you lost the original MySQL root password – nice.
                                – tanius
                                May 2 '14 at 12:29






                              • 3




                                Works with Ver 14.14 Distrib 5.5.38, for debian-linux-gnu
                                – justinpage
                                Sep 14 '14 at 1:56










                              • This worked for me on 5.5.40-0ubuntu0.14.04.1
                                – ken koehler
                                Jan 15 '15 at 19:14






                              • 19




                                Doesn't seem to work with 5.7 on newer ubuntu
                                – fuzzyTew
                                Dec 26 '16 at 2:15






                              • 2




                                sudo dpkg-reconfigure mysql-server-5.7 not working for Ubuntu 18.04 for reset root password. Any other alternate?
                                – Jagdeep Singh
                                May 21 at 6:25
















                              • 3




                                Works even when you lost the original MySQL root password – nice.
                                – tanius
                                May 2 '14 at 12:29






                              • 3




                                Works with Ver 14.14 Distrib 5.5.38, for debian-linux-gnu
                                – justinpage
                                Sep 14 '14 at 1:56










                              • This worked for me on 5.5.40-0ubuntu0.14.04.1
                                – ken koehler
                                Jan 15 '15 at 19:14






                              • 19




                                Doesn't seem to work with 5.7 on newer ubuntu
                                – fuzzyTew
                                Dec 26 '16 at 2:15






                              • 2




                                sudo dpkg-reconfigure mysql-server-5.7 not working for Ubuntu 18.04 for reset root password. Any other alternate?
                                – Jagdeep Singh
                                May 21 at 6:25










                              3




                              3




                              Works even when you lost the original MySQL root password – nice.
                              – tanius
                              May 2 '14 at 12:29




                              Works even when you lost the original MySQL root password – nice.
                              – tanius
                              May 2 '14 at 12:29




                              3




                              3




                              Works with Ver 14.14 Distrib 5.5.38, for debian-linux-gnu
                              – justinpage
                              Sep 14 '14 at 1:56




                              Works with Ver 14.14 Distrib 5.5.38, for debian-linux-gnu
                              – justinpage
                              Sep 14 '14 at 1:56












                              This worked for me on 5.5.40-0ubuntu0.14.04.1
                              – ken koehler
                              Jan 15 '15 at 19:14




                              This worked for me on 5.5.40-0ubuntu0.14.04.1
                              – ken koehler
                              Jan 15 '15 at 19:14




                              19




                              19




                              Doesn't seem to work with 5.7 on newer ubuntu
                              – fuzzyTew
                              Dec 26 '16 at 2:15




                              Doesn't seem to work with 5.7 on newer ubuntu
                              – fuzzyTew
                              Dec 26 '16 at 2:15




                              2




                              2




                              sudo dpkg-reconfigure mysql-server-5.7 not working for Ubuntu 18.04 for reset root password. Any other alternate?
                              – Jagdeep Singh
                              May 21 at 6:25






                              sudo dpkg-reconfigure mysql-server-5.7 not working for Ubuntu 18.04 for reset root password. Any other alternate?
                              – Jagdeep Singh
                              May 21 at 6:25












                              up vote
                              68
                              down vote













                              I am sharing the step by step final solution to reset a MySQL password in Linux
                              Ubuntu.



                              Reference taken from blog (dbrnd.com)



                              Step 1:
                              Stop MySQL Service.



                              sudo stop mysql


                              Step 2:
                              Kill all running mysqld.



                              sudo killall -9 mysqld


                              Step 3:
                              Starting mysqld in Safe mode.



                              sudo mysqld_safe --skip-grant-tables --skip-networking &


                              Step 4:
                              Start mysql client



                              mysql -u root


                              Step 5:
                              After successful login, please execute this command to change any password.



                              FLUSH PRIVILEGES;


                              Step 6:
                              You can update mysql root password .



                              UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';


                              Note: On MySQL 5.7, column Password is called authentication_string.



                              Step 7:
                              Please execute this command.



                              FLUSH PRIVILEGES;





                              share|improve this answer



















                              • 3




                                This actually worked for me, not the accepted answer, give it a try!
                                – Santiago Martí Olbrich
                                Oct 20 '15 at 14:49










                              • Indeed. Also, it is closer to the official documentation. In case you run into this: "ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded”, take a look at stackoverflow.com/questions/37879448/…
                                – Wtower
                                Aug 22 '16 at 9:36










                              • I also had to change mysql.user.plugin from 'auth_socket' to 'mysql_native_password' for my root user with host of 'localhost'.
                                – Brandon
                                May 17 '17 at 2:16






                              • 1




                                I had to use "sudo /etc/init.d/mysql stop" to stop the service and "UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root';" to update the password
                                – L Bahr
                                Aug 15 '17 at 1:55






                              • 1




                                authenticated _string helped
                                – Faiyaz Md Abdul
                                Nov 24 '17 at 17:49















                              up vote
                              68
                              down vote













                              I am sharing the step by step final solution to reset a MySQL password in Linux
                              Ubuntu.



                              Reference taken from blog (dbrnd.com)



                              Step 1:
                              Stop MySQL Service.



                              sudo stop mysql


                              Step 2:
                              Kill all running mysqld.



                              sudo killall -9 mysqld


                              Step 3:
                              Starting mysqld in Safe mode.



                              sudo mysqld_safe --skip-grant-tables --skip-networking &


                              Step 4:
                              Start mysql client



                              mysql -u root


                              Step 5:
                              After successful login, please execute this command to change any password.



                              FLUSH PRIVILEGES;


                              Step 6:
                              You can update mysql root password .



                              UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';


                              Note: On MySQL 5.7, column Password is called authentication_string.



                              Step 7:
                              Please execute this command.



                              FLUSH PRIVILEGES;





                              share|improve this answer



















                              • 3




                                This actually worked for me, not the accepted answer, give it a try!
                                – Santiago Martí Olbrich
                                Oct 20 '15 at 14:49










                              • Indeed. Also, it is closer to the official documentation. In case you run into this: "ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded”, take a look at stackoverflow.com/questions/37879448/…
                                – Wtower
                                Aug 22 '16 at 9:36










                              • I also had to change mysql.user.plugin from 'auth_socket' to 'mysql_native_password' for my root user with host of 'localhost'.
                                – Brandon
                                May 17 '17 at 2:16






                              • 1




                                I had to use "sudo /etc/init.d/mysql stop" to stop the service and "UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root';" to update the password
                                – L Bahr
                                Aug 15 '17 at 1:55






                              • 1




                                authenticated _string helped
                                – Faiyaz Md Abdul
                                Nov 24 '17 at 17:49













                              up vote
                              68
                              down vote










                              up vote
                              68
                              down vote









                              I am sharing the step by step final solution to reset a MySQL password in Linux
                              Ubuntu.



                              Reference taken from blog (dbrnd.com)



                              Step 1:
                              Stop MySQL Service.



                              sudo stop mysql


                              Step 2:
                              Kill all running mysqld.



                              sudo killall -9 mysqld


                              Step 3:
                              Starting mysqld in Safe mode.



                              sudo mysqld_safe --skip-grant-tables --skip-networking &


                              Step 4:
                              Start mysql client



                              mysql -u root


                              Step 5:
                              After successful login, please execute this command to change any password.



                              FLUSH PRIVILEGES;


                              Step 6:
                              You can update mysql root password .



                              UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';


                              Note: On MySQL 5.7, column Password is called authentication_string.



                              Step 7:
                              Please execute this command.



                              FLUSH PRIVILEGES;





                              share|improve this answer














                              I am sharing the step by step final solution to reset a MySQL password in Linux
                              Ubuntu.



                              Reference taken from blog (dbrnd.com)



                              Step 1:
                              Stop MySQL Service.



                              sudo stop mysql


                              Step 2:
                              Kill all running mysqld.



                              sudo killall -9 mysqld


                              Step 3:
                              Starting mysqld in Safe mode.



                              sudo mysqld_safe --skip-grant-tables --skip-networking &


                              Step 4:
                              Start mysql client



                              mysql -u root


                              Step 5:
                              After successful login, please execute this command to change any password.



                              FLUSH PRIVILEGES;


                              Step 6:
                              You can update mysql root password .



                              UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';


                              Note: On MySQL 5.7, column Password is called authentication_string.



                              Step 7:
                              Please execute this command.



                              FLUSH PRIVILEGES;






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Nov 15 '16 at 7:59

























                              answered Sep 8 '15 at 5:03









                              Anvesh

                              3,24122735




                              3,24122735








                              • 3




                                This actually worked for me, not the accepted answer, give it a try!
                                – Santiago Martí Olbrich
                                Oct 20 '15 at 14:49










                              • Indeed. Also, it is closer to the official documentation. In case you run into this: "ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded”, take a look at stackoverflow.com/questions/37879448/…
                                – Wtower
                                Aug 22 '16 at 9:36










                              • I also had to change mysql.user.plugin from 'auth_socket' to 'mysql_native_password' for my root user with host of 'localhost'.
                                – Brandon
                                May 17 '17 at 2:16






                              • 1




                                I had to use "sudo /etc/init.d/mysql stop" to stop the service and "UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root';" to update the password
                                – L Bahr
                                Aug 15 '17 at 1:55






                              • 1




                                authenticated _string helped
                                – Faiyaz Md Abdul
                                Nov 24 '17 at 17:49














                              • 3




                                This actually worked for me, not the accepted answer, give it a try!
                                – Santiago Martí Olbrich
                                Oct 20 '15 at 14:49










                              • Indeed. Also, it is closer to the official documentation. In case you run into this: "ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded”, take a look at stackoverflow.com/questions/37879448/…
                                – Wtower
                                Aug 22 '16 at 9:36










                              • I also had to change mysql.user.plugin from 'auth_socket' to 'mysql_native_password' for my root user with host of 'localhost'.
                                – Brandon
                                May 17 '17 at 2:16






                              • 1




                                I had to use "sudo /etc/init.d/mysql stop" to stop the service and "UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root';" to update the password
                                – L Bahr
                                Aug 15 '17 at 1:55






                              • 1




                                authenticated _string helped
                                – Faiyaz Md Abdul
                                Nov 24 '17 at 17:49








                              3




                              3




                              This actually worked for me, not the accepted answer, give it a try!
                              – Santiago Martí Olbrich
                              Oct 20 '15 at 14:49




                              This actually worked for me, not the accepted answer, give it a try!
                              – Santiago Martí Olbrich
                              Oct 20 '15 at 14:49












                              Indeed. Also, it is closer to the official documentation. In case you run into this: "ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded”, take a look at stackoverflow.com/questions/37879448/…
                              – Wtower
                              Aug 22 '16 at 9:36




                              Indeed. Also, it is closer to the official documentation. In case you run into this: "ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded”, take a look at stackoverflow.com/questions/37879448/…
                              – Wtower
                              Aug 22 '16 at 9:36












                              I also had to change mysql.user.plugin from 'auth_socket' to 'mysql_native_password' for my root user with host of 'localhost'.
                              – Brandon
                              May 17 '17 at 2:16




                              I also had to change mysql.user.plugin from 'auth_socket' to 'mysql_native_password' for my root user with host of 'localhost'.
                              – Brandon
                              May 17 '17 at 2:16




                              1




                              1




                              I had to use "sudo /etc/init.d/mysql stop" to stop the service and "UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root';" to update the password
                              – L Bahr
                              Aug 15 '17 at 1:55




                              I had to use "sudo /etc/init.d/mysql stop" to stop the service and "UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root';" to update the password
                              – L Bahr
                              Aug 15 '17 at 1:55




                              1




                              1




                              authenticated _string helped
                              – Faiyaz Md Abdul
                              Nov 24 '17 at 17:49




                              authenticated _string helped
                              – Faiyaz Md Abdul
                              Nov 24 '17 at 17:49










                              up vote
                              65
                              down vote













                              The only method that worked for me is the one described here (I am running ubuntu 14.04). For the sake of clarity, these are the steps I followed:




                              1. sudo vim /etc/mysql/my.cnf


                              2. Add the following lines at the end:



                                [mysqld]

                                skip-grant-tables


                              3. sudo service mysql restart


                              4. mysql -u root


                              5. use mysql


                              6. select * from mysql.user where user = 'root'; - Look at the top to determine whether the password column is called
                                password or authentication_string


                              7. UPDATE mysql.user set *password_field from above* = PASSWORD('your_new_password') where user = 'root' and host = 'localhost'; - Use the proper password column from above


                              8. FLUSH PRIVILEGES;


                              9. exit


                              10. sudo vim /etc/mysql/my.cnf


                              11. Remove the lines added in step 2 if you want to keep your security standards.


                              12. sudo service mysql restart



                              For reference : https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html






                              share|improve this answer



















                              • 5




                                Finally, this worked for me! I'm running MySQL 5.7.18 on Ubuntu 16.04. I tried dpkg-reconfigure, Anvesh's answer, Christian Mark's answer, and even the instructions on MySQL's help page.
                                – mbuc91
                                May 11 '17 at 5:15






                              • 7




                                I had to run UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root'; instead for line 5.
                                – mbuc91
                                May 11 '17 at 5:21










                              • The only solution that worked for me. I have Ubuntu 17.04 and mysql 5.7
                                – Mohamed
                                Nov 20 '17 at 1:52










                              • In point 6 you have to add user should be this way select * from mysql.user where user = 'root';
                                – user615274
                                May 17 at 2:50










                              • Sad this does not work for me mysql 5.7.22 ubuntu 18.04
                                – user615274
                                May 17 at 2:55















                              up vote
                              65
                              down vote













                              The only method that worked for me is the one described here (I am running ubuntu 14.04). For the sake of clarity, these are the steps I followed:




                              1. sudo vim /etc/mysql/my.cnf


                              2. Add the following lines at the end:



                                [mysqld]

                                skip-grant-tables


                              3. sudo service mysql restart


                              4. mysql -u root


                              5. use mysql


                              6. select * from mysql.user where user = 'root'; - Look at the top to determine whether the password column is called
                                password or authentication_string


                              7. UPDATE mysql.user set *password_field from above* = PASSWORD('your_new_password') where user = 'root' and host = 'localhost'; - Use the proper password column from above


                              8. FLUSH PRIVILEGES;


                              9. exit


                              10. sudo vim /etc/mysql/my.cnf


                              11. Remove the lines added in step 2 if you want to keep your security standards.


                              12. sudo service mysql restart



                              For reference : https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html






                              share|improve this answer



















                              • 5




                                Finally, this worked for me! I'm running MySQL 5.7.18 on Ubuntu 16.04. I tried dpkg-reconfigure, Anvesh's answer, Christian Mark's answer, and even the instructions on MySQL's help page.
                                – mbuc91
                                May 11 '17 at 5:15






                              • 7




                                I had to run UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root'; instead for line 5.
                                – mbuc91
                                May 11 '17 at 5:21










                              • The only solution that worked for me. I have Ubuntu 17.04 and mysql 5.7
                                – Mohamed
                                Nov 20 '17 at 1:52










                              • In point 6 you have to add user should be this way select * from mysql.user where user = 'root';
                                – user615274
                                May 17 at 2:50










                              • Sad this does not work for me mysql 5.7.22 ubuntu 18.04
                                – user615274
                                May 17 at 2:55













                              up vote
                              65
                              down vote










                              up vote
                              65
                              down vote









                              The only method that worked for me is the one described here (I am running ubuntu 14.04). For the sake of clarity, these are the steps I followed:




                              1. sudo vim /etc/mysql/my.cnf


                              2. Add the following lines at the end:



                                [mysqld]

                                skip-grant-tables


                              3. sudo service mysql restart


                              4. mysql -u root


                              5. use mysql


                              6. select * from mysql.user where user = 'root'; - Look at the top to determine whether the password column is called
                                password or authentication_string


                              7. UPDATE mysql.user set *password_field from above* = PASSWORD('your_new_password') where user = 'root' and host = 'localhost'; - Use the proper password column from above


                              8. FLUSH PRIVILEGES;


                              9. exit


                              10. sudo vim /etc/mysql/my.cnf


                              11. Remove the lines added in step 2 if you want to keep your security standards.


                              12. sudo service mysql restart



                              For reference : https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html






                              share|improve this answer














                              The only method that worked for me is the one described here (I am running ubuntu 14.04). For the sake of clarity, these are the steps I followed:




                              1. sudo vim /etc/mysql/my.cnf


                              2. Add the following lines at the end:



                                [mysqld]

                                skip-grant-tables


                              3. sudo service mysql restart


                              4. mysql -u root


                              5. use mysql


                              6. select * from mysql.user where user = 'root'; - Look at the top to determine whether the password column is called
                                password or authentication_string


                              7. UPDATE mysql.user set *password_field from above* = PASSWORD('your_new_password') where user = 'root' and host = 'localhost'; - Use the proper password column from above


                              8. FLUSH PRIVILEGES;


                              9. exit


                              10. sudo vim /etc/mysql/my.cnf


                              11. Remove the lines added in step 2 if you want to keep your security standards.


                              12. sudo service mysql restart



                              For reference : https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jun 5 at 13:07









                              Ravindra Gullapalli

                              7,81433161




                              7,81433161










                              answered Jul 31 '15 at 17:28









                              narko

                              1,4571624




                              1,4571624








                              • 5




                                Finally, this worked for me! I'm running MySQL 5.7.18 on Ubuntu 16.04. I tried dpkg-reconfigure, Anvesh's answer, Christian Mark's answer, and even the instructions on MySQL's help page.
                                – mbuc91
                                May 11 '17 at 5:15






                              • 7




                                I had to run UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root'; instead for line 5.
                                – mbuc91
                                May 11 '17 at 5:21










                              • The only solution that worked for me. I have Ubuntu 17.04 and mysql 5.7
                                – Mohamed
                                Nov 20 '17 at 1:52










                              • In point 6 you have to add user should be this way select * from mysql.user where user = 'root';
                                – user615274
                                May 17 at 2:50










                              • Sad this does not work for me mysql 5.7.22 ubuntu 18.04
                                – user615274
                                May 17 at 2:55














                              • 5




                                Finally, this worked for me! I'm running MySQL 5.7.18 on Ubuntu 16.04. I tried dpkg-reconfigure, Anvesh's answer, Christian Mark's answer, and even the instructions on MySQL's help page.
                                – mbuc91
                                May 11 '17 at 5:15






                              • 7




                                I had to run UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root'; instead for line 5.
                                – mbuc91
                                May 11 '17 at 5:21










                              • The only solution that worked for me. I have Ubuntu 17.04 and mysql 5.7
                                – Mohamed
                                Nov 20 '17 at 1:52










                              • In point 6 you have to add user should be this way select * from mysql.user where user = 'root';
                                – user615274
                                May 17 at 2:50










                              • Sad this does not work for me mysql 5.7.22 ubuntu 18.04
                                – user615274
                                May 17 at 2:55








                              5




                              5




                              Finally, this worked for me! I'm running MySQL 5.7.18 on Ubuntu 16.04. I tried dpkg-reconfigure, Anvesh's answer, Christian Mark's answer, and even the instructions on MySQL's help page.
                              – mbuc91
                              May 11 '17 at 5:15




                              Finally, this worked for me! I'm running MySQL 5.7.18 on Ubuntu 16.04. I tried dpkg-reconfigure, Anvesh's answer, Christian Mark's answer, and even the instructions on MySQL's help page.
                              – mbuc91
                              May 11 '17 at 5:15




                              7




                              7




                              I had to run UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root'; instead for line 5.
                              – mbuc91
                              May 11 '17 at 5:21




                              I had to run UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root'; instead for line 5.
                              – mbuc91
                              May 11 '17 at 5:21












                              The only solution that worked for me. I have Ubuntu 17.04 and mysql 5.7
                              – Mohamed
                              Nov 20 '17 at 1:52




                              The only solution that worked for me. I have Ubuntu 17.04 and mysql 5.7
                              – Mohamed
                              Nov 20 '17 at 1:52












                              In point 6 you have to add user should be this way select * from mysql.user where user = 'root';
                              – user615274
                              May 17 at 2:50




                              In point 6 you have to add user should be this way select * from mysql.user where user = 'root';
                              – user615274
                              May 17 at 2:50












                              Sad this does not work for me mysql 5.7.22 ubuntu 18.04
                              – user615274
                              May 17 at 2:55




                              Sad this does not work for me mysql 5.7.22 ubuntu 18.04
                              – user615274
                              May 17 at 2:55










                              up vote
                              33
                              down vote













                              Change the MySQL root password.



                              This method exposes the password to the command-line history, these commands should be run as root.





                              1. Login through mysql command line tool:



                                mysql -uroot -poldpassword



                              2. Run this command:



                                SET PASSWORD FOR root@'localhost' = PASSWORD('newpassword');



                              or





                              1. Run this command, which sets a password for the current user ('root' for this case) :




                                SET PASSWORD = PASSWORD('newpassword');









                              share|improve this answer



























                                up vote
                                33
                                down vote













                                Change the MySQL root password.



                                This method exposes the password to the command-line history, these commands should be run as root.





                                1. Login through mysql command line tool:



                                  mysql -uroot -poldpassword



                                2. Run this command:



                                  SET PASSWORD FOR root@'localhost' = PASSWORD('newpassword');



                                or





                                1. Run this command, which sets a password for the current user ('root' for this case) :




                                  SET PASSWORD = PASSWORD('newpassword');









                                share|improve this answer

























                                  up vote
                                  33
                                  down vote










                                  up vote
                                  33
                                  down vote









                                  Change the MySQL root password.



                                  This method exposes the password to the command-line history, these commands should be run as root.





                                  1. Login through mysql command line tool:



                                    mysql -uroot -poldpassword



                                  2. Run this command:



                                    SET PASSWORD FOR root@'localhost' = PASSWORD('newpassword');



                                  or





                                  1. Run this command, which sets a password for the current user ('root' for this case) :




                                    SET PASSWORD = PASSWORD('newpassword');









                                  share|improve this answer














                                  Change the MySQL root password.



                                  This method exposes the password to the command-line history, these commands should be run as root.





                                  1. Login through mysql command line tool:



                                    mysql -uroot -poldpassword



                                  2. Run this command:



                                    SET PASSWORD FOR root@'localhost' = PASSWORD('newpassword');



                                  or





                                  1. Run this command, which sets a password for the current user ('root' for this case) :




                                    SET PASSWORD = PASSWORD('newpassword');










                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Sep 10 '14 at 14:29









                                  Logan Murphy

                                  4,45821735




                                  4,45821735










                                  answered Oct 26 '13 at 20:22









                                  faisalbhagat

                                  1,6341823




                                  1,6341823






















                                      up vote
                                      27
                                      down vote













                                      What worked for me (Ubuntu 16.04, mysql 5.7):



                                      Stop MySQL



                                      sudo service mysql stop


                                      Make MySQL service directory.



                                      sudo mkdir /var/run/mysqld


                                      Give MySQL user permission to write to the service directory.



                                      sudo chown mysql: /var/run/mysqld


                                      Start MySQL manually, without permission checks or networking.



                                      sudo mysqld_safe --skip-grant-tables --skip-networking &


                                      On another console, log in without a password.



                                      mysql -uroot mysql


                                      Then:



                                      UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
                                      EXIT;


                                      Turn off MySQL.



                                      sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                      Start the MySQL service normally.



                                      sudo service mysql start





                                      share|improve this answer





















                                      • The other ways did not work for me but this one (thanks!), or you can also go here rricketts.com/reset-root-password-mysql-5-7-ubuntu-16-04-lts
                                        – Dung
                                        Dec 7 '17 at 17:25








                                      • 5




                                        Very useful ! In my specific case (Ubuntu 18.04 LTS), I had to replace the host '%' to 'localhost'
                                        – FredericK
                                        May 7 at 13:16















                                      up vote
                                      27
                                      down vote













                                      What worked for me (Ubuntu 16.04, mysql 5.7):



                                      Stop MySQL



                                      sudo service mysql stop


                                      Make MySQL service directory.



                                      sudo mkdir /var/run/mysqld


                                      Give MySQL user permission to write to the service directory.



                                      sudo chown mysql: /var/run/mysqld


                                      Start MySQL manually, without permission checks or networking.



                                      sudo mysqld_safe --skip-grant-tables --skip-networking &


                                      On another console, log in without a password.



                                      mysql -uroot mysql


                                      Then:



                                      UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
                                      EXIT;


                                      Turn off MySQL.



                                      sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                      Start the MySQL service normally.



                                      sudo service mysql start





                                      share|improve this answer





















                                      • The other ways did not work for me but this one (thanks!), or you can also go here rricketts.com/reset-root-password-mysql-5-7-ubuntu-16-04-lts
                                        – Dung
                                        Dec 7 '17 at 17:25








                                      • 5




                                        Very useful ! In my specific case (Ubuntu 18.04 LTS), I had to replace the host '%' to 'localhost'
                                        – FredericK
                                        May 7 at 13:16













                                      up vote
                                      27
                                      down vote










                                      up vote
                                      27
                                      down vote









                                      What worked for me (Ubuntu 16.04, mysql 5.7):



                                      Stop MySQL



                                      sudo service mysql stop


                                      Make MySQL service directory.



                                      sudo mkdir /var/run/mysqld


                                      Give MySQL user permission to write to the service directory.



                                      sudo chown mysql: /var/run/mysqld


                                      Start MySQL manually, without permission checks or networking.



                                      sudo mysqld_safe --skip-grant-tables --skip-networking &


                                      On another console, log in without a password.



                                      mysql -uroot mysql


                                      Then:



                                      UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
                                      EXIT;


                                      Turn off MySQL.



                                      sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                      Start the MySQL service normally.



                                      sudo service mysql start





                                      share|improve this answer












                                      What worked for me (Ubuntu 16.04, mysql 5.7):



                                      Stop MySQL



                                      sudo service mysql stop


                                      Make MySQL service directory.



                                      sudo mkdir /var/run/mysqld


                                      Give MySQL user permission to write to the service directory.



                                      sudo chown mysql: /var/run/mysqld


                                      Start MySQL manually, without permission checks or networking.



                                      sudo mysqld_safe --skip-grant-tables --skip-networking &


                                      On another console, log in without a password.



                                      mysql -uroot mysql


                                      Then:



                                      UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
                                      EXIT;


                                      Turn off MySQL.



                                      sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                      Start the MySQL service normally.



                                      sudo service mysql start






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Sep 6 '17 at 13:41









                                      fabriciofreitag

                                      1,275816




                                      1,275816












                                      • The other ways did not work for me but this one (thanks!), or you can also go here rricketts.com/reset-root-password-mysql-5-7-ubuntu-16-04-lts
                                        – Dung
                                        Dec 7 '17 at 17:25








                                      • 5




                                        Very useful ! In my specific case (Ubuntu 18.04 LTS), I had to replace the host '%' to 'localhost'
                                        – FredericK
                                        May 7 at 13:16


















                                      • The other ways did not work for me but this one (thanks!), or you can also go here rricketts.com/reset-root-password-mysql-5-7-ubuntu-16-04-lts
                                        – Dung
                                        Dec 7 '17 at 17:25








                                      • 5




                                        Very useful ! In my specific case (Ubuntu 18.04 LTS), I had to replace the host '%' to 'localhost'
                                        – FredericK
                                        May 7 at 13:16
















                                      The other ways did not work for me but this one (thanks!), or you can also go here rricketts.com/reset-root-password-mysql-5-7-ubuntu-16-04-lts
                                      – Dung
                                      Dec 7 '17 at 17:25






                                      The other ways did not work for me but this one (thanks!), or you can also go here rricketts.com/reset-root-password-mysql-5-7-ubuntu-16-04-lts
                                      – Dung
                                      Dec 7 '17 at 17:25






                                      5




                                      5




                                      Very useful ! In my specific case (Ubuntu 18.04 LTS), I had to replace the host '%' to 'localhost'
                                      – FredericK
                                      May 7 at 13:16




                                      Very useful ! In my specific case (Ubuntu 18.04 LTS), I had to replace the host '%' to 'localhost'
                                      – FredericK
                                      May 7 at 13:16










                                      up vote
                                      12
                                      down vote













                                      If you would like to change the MySQL root password, in a terminal enter:



                                      sudo dpkg-reconfigure mysql-server-5.5



                                      The MySQL daemon will be stopped, and you will be prompted to enter a new password.






                                      share|improve this answer

















                                      • 1




                                        This is a much better way to do it. I was unable to run the previous commands because of some mysql error...
                                        – Andy
                                        Jan 28 '16 at 3:46










                                      • sudo dpkg-reconfigure mysql-server-5.7 on ubuntu 16.04
                                        – Nick Barrett
                                        Feb 28 '17 at 6:42






                                      • 1




                                        I ran sudo dpkg-reconfigure mysql-server-5.7 on Ubuntu 16.04, it didn't prompt to enter a new password.
                                        – Franck Dernoncourt
                                        Jan 22 at 22:32










                                      • If it says mysql-server is broken or not fully installed, one can use sudo apt purge mysql* and sudo apt install mysql-server
                                        – Pavel
                                        Oct 22 at 7:30















                                      up vote
                                      12
                                      down vote













                                      If you would like to change the MySQL root password, in a terminal enter:



                                      sudo dpkg-reconfigure mysql-server-5.5



                                      The MySQL daemon will be stopped, and you will be prompted to enter a new password.






                                      share|improve this answer

















                                      • 1




                                        This is a much better way to do it. I was unable to run the previous commands because of some mysql error...
                                        – Andy
                                        Jan 28 '16 at 3:46










                                      • sudo dpkg-reconfigure mysql-server-5.7 on ubuntu 16.04
                                        – Nick Barrett
                                        Feb 28 '17 at 6:42






                                      • 1




                                        I ran sudo dpkg-reconfigure mysql-server-5.7 on Ubuntu 16.04, it didn't prompt to enter a new password.
                                        – Franck Dernoncourt
                                        Jan 22 at 22:32










                                      • If it says mysql-server is broken or not fully installed, one can use sudo apt purge mysql* and sudo apt install mysql-server
                                        – Pavel
                                        Oct 22 at 7:30













                                      up vote
                                      12
                                      down vote










                                      up vote
                                      12
                                      down vote









                                      If you would like to change the MySQL root password, in a terminal enter:



                                      sudo dpkg-reconfigure mysql-server-5.5



                                      The MySQL daemon will be stopped, and you will be prompted to enter a new password.






                                      share|improve this answer












                                      If you would like to change the MySQL root password, in a terminal enter:



                                      sudo dpkg-reconfigure mysql-server-5.5



                                      The MySQL daemon will be stopped, and you will be prompted to enter a new password.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Dec 6 '15 at 10:15









                                      user2206324

                                      31125




                                      31125








                                      • 1




                                        This is a much better way to do it. I was unable to run the previous commands because of some mysql error...
                                        – Andy
                                        Jan 28 '16 at 3:46










                                      • sudo dpkg-reconfigure mysql-server-5.7 on ubuntu 16.04
                                        – Nick Barrett
                                        Feb 28 '17 at 6:42






                                      • 1




                                        I ran sudo dpkg-reconfigure mysql-server-5.7 on Ubuntu 16.04, it didn't prompt to enter a new password.
                                        – Franck Dernoncourt
                                        Jan 22 at 22:32










                                      • If it says mysql-server is broken or not fully installed, one can use sudo apt purge mysql* and sudo apt install mysql-server
                                        – Pavel
                                        Oct 22 at 7:30














                                      • 1




                                        This is a much better way to do it. I was unable to run the previous commands because of some mysql error...
                                        – Andy
                                        Jan 28 '16 at 3:46










                                      • sudo dpkg-reconfigure mysql-server-5.7 on ubuntu 16.04
                                        – Nick Barrett
                                        Feb 28 '17 at 6:42






                                      • 1




                                        I ran sudo dpkg-reconfigure mysql-server-5.7 on Ubuntu 16.04, it didn't prompt to enter a new password.
                                        – Franck Dernoncourt
                                        Jan 22 at 22:32










                                      • If it says mysql-server is broken or not fully installed, one can use sudo apt purge mysql* and sudo apt install mysql-server
                                        – Pavel
                                        Oct 22 at 7:30








                                      1




                                      1




                                      This is a much better way to do it. I was unable to run the previous commands because of some mysql error...
                                      – Andy
                                      Jan 28 '16 at 3:46




                                      This is a much better way to do it. I was unable to run the previous commands because of some mysql error...
                                      – Andy
                                      Jan 28 '16 at 3:46












                                      sudo dpkg-reconfigure mysql-server-5.7 on ubuntu 16.04
                                      – Nick Barrett
                                      Feb 28 '17 at 6:42




                                      sudo dpkg-reconfigure mysql-server-5.7 on ubuntu 16.04
                                      – Nick Barrett
                                      Feb 28 '17 at 6:42




                                      1




                                      1




                                      I ran sudo dpkg-reconfigure mysql-server-5.7 on Ubuntu 16.04, it didn't prompt to enter a new password.
                                      – Franck Dernoncourt
                                      Jan 22 at 22:32




                                      I ran sudo dpkg-reconfigure mysql-server-5.7 on Ubuntu 16.04, it didn't prompt to enter a new password.
                                      – Franck Dernoncourt
                                      Jan 22 at 22:32












                                      If it says mysql-server is broken or not fully installed, one can use sudo apt purge mysql* and sudo apt install mysql-server
                                      – Pavel
                                      Oct 22 at 7:30




                                      If it says mysql-server is broken or not fully installed, one can use sudo apt purge mysql* and sudo apt install mysql-server
                                      – Pavel
                                      Oct 22 at 7:30










                                      up vote
                                      11
                                      down vote













                                      I faced problems with ubuntu 18.04 and mysql 5.7, this is the solution



                                      MYSQL-SERVER >= 5.7



                                      sudo mysql -uroot -p
                                      USE mysql;
                                      UPDATE user SET authentication_string=PASSWORD('YOUR_PASSWORD') WHERE User='root';
                                      UPDATE user SET plugin="mysql_native_password";
                                      FLUSH PRIVILEGES;
                                      quit;


                                      MYSQL-SERVER < 5.7



                                      sudo mysql -uroot -p
                                      USE mysql;
                                      UPDATE user SET password=PASSWORD('YOUR_PASSWORD') WHERE User='root';
                                      UPDATE user SET plugin="mysql_native_password";
                                      FLUSH PRIVILEGES;
                                      quit;





                                      share|improve this answer

















                                      • 1




                                        Thanks, I'm also running Ubuntu 18.04 here and the MYSQL-SERVER >= 5.7 version was the only thing that actually solved the problem
                                        – Miguelgraz
                                        Jul 4 at 12:41






                                      • 1




                                        Good thing it was helpful, share it with anyone who has the same problem.
                                        – Jerfeson Guerreiro
                                        Jul 5 at 0:03










                                      • So para constar acho que o root do mysql so é acessado pelo sudo. Pelo menos foi o que funcionou pra mim.
                                        – Ismael Junior
                                        Jul 19 at 18:52















                                      up vote
                                      11
                                      down vote













                                      I faced problems with ubuntu 18.04 and mysql 5.7, this is the solution



                                      MYSQL-SERVER >= 5.7



                                      sudo mysql -uroot -p
                                      USE mysql;
                                      UPDATE user SET authentication_string=PASSWORD('YOUR_PASSWORD') WHERE User='root';
                                      UPDATE user SET plugin="mysql_native_password";
                                      FLUSH PRIVILEGES;
                                      quit;


                                      MYSQL-SERVER < 5.7



                                      sudo mysql -uroot -p
                                      USE mysql;
                                      UPDATE user SET password=PASSWORD('YOUR_PASSWORD') WHERE User='root';
                                      UPDATE user SET plugin="mysql_native_password";
                                      FLUSH PRIVILEGES;
                                      quit;





                                      share|improve this answer

















                                      • 1




                                        Thanks, I'm also running Ubuntu 18.04 here and the MYSQL-SERVER >= 5.7 version was the only thing that actually solved the problem
                                        – Miguelgraz
                                        Jul 4 at 12:41






                                      • 1




                                        Good thing it was helpful, share it with anyone who has the same problem.
                                        – Jerfeson Guerreiro
                                        Jul 5 at 0:03










                                      • So para constar acho que o root do mysql so é acessado pelo sudo. Pelo menos foi o que funcionou pra mim.
                                        – Ismael Junior
                                        Jul 19 at 18:52













                                      up vote
                                      11
                                      down vote










                                      up vote
                                      11
                                      down vote









                                      I faced problems with ubuntu 18.04 and mysql 5.7, this is the solution



                                      MYSQL-SERVER >= 5.7



                                      sudo mysql -uroot -p
                                      USE mysql;
                                      UPDATE user SET authentication_string=PASSWORD('YOUR_PASSWORD') WHERE User='root';
                                      UPDATE user SET plugin="mysql_native_password";
                                      FLUSH PRIVILEGES;
                                      quit;


                                      MYSQL-SERVER < 5.7



                                      sudo mysql -uroot -p
                                      USE mysql;
                                      UPDATE user SET password=PASSWORD('YOUR_PASSWORD') WHERE User='root';
                                      UPDATE user SET plugin="mysql_native_password";
                                      FLUSH PRIVILEGES;
                                      quit;





                                      share|improve this answer












                                      I faced problems with ubuntu 18.04 and mysql 5.7, this is the solution



                                      MYSQL-SERVER >= 5.7



                                      sudo mysql -uroot -p
                                      USE mysql;
                                      UPDATE user SET authentication_string=PASSWORD('YOUR_PASSWORD') WHERE User='root';
                                      UPDATE user SET plugin="mysql_native_password";
                                      FLUSH PRIVILEGES;
                                      quit;


                                      MYSQL-SERVER < 5.7



                                      sudo mysql -uroot -p
                                      USE mysql;
                                      UPDATE user SET password=PASSWORD('YOUR_PASSWORD') WHERE User='root';
                                      UPDATE user SET plugin="mysql_native_password";
                                      FLUSH PRIVILEGES;
                                      quit;






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jun 25 at 12:21









                                      Jerfeson Guerreiro

                                      137212




                                      137212








                                      • 1




                                        Thanks, I'm also running Ubuntu 18.04 here and the MYSQL-SERVER >= 5.7 version was the only thing that actually solved the problem
                                        – Miguelgraz
                                        Jul 4 at 12:41






                                      • 1




                                        Good thing it was helpful, share it with anyone who has the same problem.
                                        – Jerfeson Guerreiro
                                        Jul 5 at 0:03










                                      • So para constar acho que o root do mysql so é acessado pelo sudo. Pelo menos foi o que funcionou pra mim.
                                        – Ismael Junior
                                        Jul 19 at 18:52














                                      • 1




                                        Thanks, I'm also running Ubuntu 18.04 here and the MYSQL-SERVER >= 5.7 version was the only thing that actually solved the problem
                                        – Miguelgraz
                                        Jul 4 at 12:41






                                      • 1




                                        Good thing it was helpful, share it with anyone who has the same problem.
                                        – Jerfeson Guerreiro
                                        Jul 5 at 0:03










                                      • So para constar acho que o root do mysql so é acessado pelo sudo. Pelo menos foi o que funcionou pra mim.
                                        – Ismael Junior
                                        Jul 19 at 18:52








                                      1




                                      1




                                      Thanks, I'm also running Ubuntu 18.04 here and the MYSQL-SERVER >= 5.7 version was the only thing that actually solved the problem
                                      – Miguelgraz
                                      Jul 4 at 12:41




                                      Thanks, I'm also running Ubuntu 18.04 here and the MYSQL-SERVER >= 5.7 version was the only thing that actually solved the problem
                                      – Miguelgraz
                                      Jul 4 at 12:41




                                      1




                                      1




                                      Good thing it was helpful, share it with anyone who has the same problem.
                                      – Jerfeson Guerreiro
                                      Jul 5 at 0:03




                                      Good thing it was helpful, share it with anyone who has the same problem.
                                      – Jerfeson Guerreiro
                                      Jul 5 at 0:03












                                      So para constar acho que o root do mysql so é acessado pelo sudo. Pelo menos foi o que funcionou pra mim.
                                      – Ismael Junior
                                      Jul 19 at 18:52




                                      So para constar acho que o root do mysql so é acessado pelo sudo. Pelo menos foi o que funcionou pra mim.
                                      – Ismael Junior
                                      Jul 19 at 18:52










                                      up vote
                                      9
                                      down vote













                                      This works like charm I did it for Ubuntu 16.04.
                                      Full credit to below link as I got it from there.
                                      [https://coderwall.com/p/j9btlg/reset-the-mysql-5-7-root-password-in-ubuntu-16-04-lts][1]



                                      Stop MySQL



                                      sudo service mysql stop


                                      Make MySQL service directory.
                                      sudo mkdir /var/run/mysqld



                                      Give MySQL user permission to write to the service directory.



                                      sudo chown mysql: /var/run/mysqld


                                      Start MySQL manually, without permission checks or networking.



                                      sudo mysqld_safe --skip-grant-tables --skip-networking &


                                      Log in without a password.



                                      mysql -uroot mysql


                                      Update the password for the root user.
                                      make sure at atleast root account gets updated by the below query.
                                      make some selection and check the existing values if you like



                                      UPDATE mysql.user SET 
                                      authentication_string=PASSWORD('YOURNEWPASSWORD'),
                                      plugin='mysql_native_password' WHERE User='root' AND Host='%';
                                      EXIT;


                                      Turn off MySQL.



                                      sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                      Start the MySQL service normally.



                                      sudo service mysql start





                                      share|improve this answer



























                                        up vote
                                        9
                                        down vote













                                        This works like charm I did it for Ubuntu 16.04.
                                        Full credit to below link as I got it from there.
                                        [https://coderwall.com/p/j9btlg/reset-the-mysql-5-7-root-password-in-ubuntu-16-04-lts][1]



                                        Stop MySQL



                                        sudo service mysql stop


                                        Make MySQL service directory.
                                        sudo mkdir /var/run/mysqld



                                        Give MySQL user permission to write to the service directory.



                                        sudo chown mysql: /var/run/mysqld


                                        Start MySQL manually, without permission checks or networking.



                                        sudo mysqld_safe --skip-grant-tables --skip-networking &


                                        Log in without a password.



                                        mysql -uroot mysql


                                        Update the password for the root user.
                                        make sure at atleast root account gets updated by the below query.
                                        make some selection and check the existing values if you like



                                        UPDATE mysql.user SET 
                                        authentication_string=PASSWORD('YOURNEWPASSWORD'),
                                        plugin='mysql_native_password' WHERE User='root' AND Host='%';
                                        EXIT;


                                        Turn off MySQL.



                                        sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                        Start the MySQL service normally.



                                        sudo service mysql start





                                        share|improve this answer

























                                          up vote
                                          9
                                          down vote










                                          up vote
                                          9
                                          down vote









                                          This works like charm I did it for Ubuntu 16.04.
                                          Full credit to below link as I got it from there.
                                          [https://coderwall.com/p/j9btlg/reset-the-mysql-5-7-root-password-in-ubuntu-16-04-lts][1]



                                          Stop MySQL



                                          sudo service mysql stop


                                          Make MySQL service directory.
                                          sudo mkdir /var/run/mysqld



                                          Give MySQL user permission to write to the service directory.



                                          sudo chown mysql: /var/run/mysqld


                                          Start MySQL manually, without permission checks or networking.



                                          sudo mysqld_safe --skip-grant-tables --skip-networking &


                                          Log in without a password.



                                          mysql -uroot mysql


                                          Update the password for the root user.
                                          make sure at atleast root account gets updated by the below query.
                                          make some selection and check the existing values if you like



                                          UPDATE mysql.user SET 
                                          authentication_string=PASSWORD('YOURNEWPASSWORD'),
                                          plugin='mysql_native_password' WHERE User='root' AND Host='%';
                                          EXIT;


                                          Turn off MySQL.



                                          sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                          Start the MySQL service normally.



                                          sudo service mysql start





                                          share|improve this answer














                                          This works like charm I did it for Ubuntu 16.04.
                                          Full credit to below link as I got it from there.
                                          [https://coderwall.com/p/j9btlg/reset-the-mysql-5-7-root-password-in-ubuntu-16-04-lts][1]



                                          Stop MySQL



                                          sudo service mysql stop


                                          Make MySQL service directory.
                                          sudo mkdir /var/run/mysqld



                                          Give MySQL user permission to write to the service directory.



                                          sudo chown mysql: /var/run/mysqld


                                          Start MySQL manually, without permission checks or networking.



                                          sudo mysqld_safe --skip-grant-tables --skip-networking &


                                          Log in without a password.



                                          mysql -uroot mysql


                                          Update the password for the root user.
                                          make sure at atleast root account gets updated by the below query.
                                          make some selection and check the existing values if you like



                                          UPDATE mysql.user SET 
                                          authentication_string=PASSWORD('YOURNEWPASSWORD'),
                                          plugin='mysql_native_password' WHERE User='root' AND Host='%';
                                          EXIT;


                                          Turn off MySQL.



                                          sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                          Start the MySQL service normally.



                                          sudo service mysql start






                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Sep 20 '17 at 19:44

























                                          answered Sep 20 '17 at 19:39









                                          lizard

                                          9614




                                          9614






















                                              up vote
                                              8
                                              down vote














                                              1. Stop MySQL
                                                sudo service mysql stop


                                              2. Make MySQL service directory.
                                                sudo mkdir /var/run/mysqld


                                              3. Give MySQL user permission to write to the service directory.
                                                sudo chown mysql: /var/run/mysqld


                                              4. Start MySQL manually, without permission checks or networking.
                                                sudo mysqld_safe --skip-grant-tables --skip-networking &



                                              5.Log in without a password.
                                              mysql -uroot mysql



                                              6.Update the password for the root user.



                                              UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
                                              EXIT;




                                              1. Turn off MySQL.
                                                sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                              2. Start the MySQL service normally.
                                                sudo service mysql start







                                              share|improve this answer





















                                              • Hi, this answer works for me, but I had to use another command: UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root'; without AND Host='%'. Thanks!
                                                – David Corral
                                                May 22 at 17:51















                                              up vote
                                              8
                                              down vote














                                              1. Stop MySQL
                                                sudo service mysql stop


                                              2. Make MySQL service directory.
                                                sudo mkdir /var/run/mysqld


                                              3. Give MySQL user permission to write to the service directory.
                                                sudo chown mysql: /var/run/mysqld


                                              4. Start MySQL manually, without permission checks or networking.
                                                sudo mysqld_safe --skip-grant-tables --skip-networking &



                                              5.Log in without a password.
                                              mysql -uroot mysql



                                              6.Update the password for the root user.



                                              UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
                                              EXIT;




                                              1. Turn off MySQL.
                                                sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                              2. Start the MySQL service normally.
                                                sudo service mysql start







                                              share|improve this answer





















                                              • Hi, this answer works for me, but I had to use another command: UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root'; without AND Host='%'. Thanks!
                                                – David Corral
                                                May 22 at 17:51













                                              up vote
                                              8
                                              down vote










                                              up vote
                                              8
                                              down vote










                                              1. Stop MySQL
                                                sudo service mysql stop


                                              2. Make MySQL service directory.
                                                sudo mkdir /var/run/mysqld


                                              3. Give MySQL user permission to write to the service directory.
                                                sudo chown mysql: /var/run/mysqld


                                              4. Start MySQL manually, without permission checks or networking.
                                                sudo mysqld_safe --skip-grant-tables --skip-networking &



                                              5.Log in without a password.
                                              mysql -uroot mysql



                                              6.Update the password for the root user.



                                              UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
                                              EXIT;




                                              1. Turn off MySQL.
                                                sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                              2. Start the MySQL service normally.
                                                sudo service mysql start







                                              share|improve this answer













                                              1. Stop MySQL
                                                sudo service mysql stop


                                              2. Make MySQL service directory.
                                                sudo mkdir /var/run/mysqld


                                              3. Give MySQL user permission to write to the service directory.
                                                sudo chown mysql: /var/run/mysqld


                                              4. Start MySQL manually, without permission checks or networking.
                                                sudo mysqld_safe --skip-grant-tables --skip-networking &



                                              5.Log in without a password.
                                              mysql -uroot mysql



                                              6.Update the password for the root user.



                                              UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
                                              EXIT;




                                              1. Turn off MySQL.
                                                sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                              2. Start the MySQL service normally.
                                                sudo service mysql start








                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Apr 2 at 11:11









                                              Rahul Raveendran

                                              8111




                                              8111












                                              • Hi, this answer works for me, but I had to use another command: UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root'; without AND Host='%'. Thanks!
                                                – David Corral
                                                May 22 at 17:51


















                                              • Hi, this answer works for me, but I had to use another command: UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root'; without AND Host='%'. Thanks!
                                                – David Corral
                                                May 22 at 17:51
















                                              Hi, this answer works for me, but I had to use another command: UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root'; without AND Host='%'. Thanks!
                                              – David Corral
                                              May 22 at 17:51




                                              Hi, this answer works for me, but I had to use another command: UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root'; without AND Host='%'. Thanks!
                                              – David Corral
                                              May 22 at 17:51










                                              up vote
                                              7
                                              down vote













                                              This solution belongs to the previous version of MySQL.
                                              By logging in to MySQL using socket authentication, you can do it.



                                              sudo mysql -u root


                                              Then the following command could be run.



                                              ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';


                                              Details are available here .






                                              share|improve this answer

















                                              • 1




                                                I couldn't login as sudo mysql -u root but I was able to do it as sudo mysql and run the ALTER USER command.
                                                – itsols
                                                Oct 24 at 7:59






                                              • 1




                                                Life savior. Quick and clean.
                                                – Marcelo Agimóvel
                                                Nov 4 at 0:08















                                              up vote
                                              7
                                              down vote













                                              This solution belongs to the previous version of MySQL.
                                              By logging in to MySQL using socket authentication, you can do it.



                                              sudo mysql -u root


                                              Then the following command could be run.



                                              ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';


                                              Details are available here .






                                              share|improve this answer

















                                              • 1




                                                I couldn't login as sudo mysql -u root but I was able to do it as sudo mysql and run the ALTER USER command.
                                                – itsols
                                                Oct 24 at 7:59






                                              • 1




                                                Life savior. Quick and clean.
                                                – Marcelo Agimóvel
                                                Nov 4 at 0:08













                                              up vote
                                              7
                                              down vote










                                              up vote
                                              7
                                              down vote









                                              This solution belongs to the previous version of MySQL.
                                              By logging in to MySQL using socket authentication, you can do it.



                                              sudo mysql -u root


                                              Then the following command could be run.



                                              ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';


                                              Details are available here .






                                              share|improve this answer












                                              This solution belongs to the previous version of MySQL.
                                              By logging in to MySQL using socket authentication, you can do it.



                                              sudo mysql -u root


                                              Then the following command could be run.



                                              ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';


                                              Details are available here .







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Jul 20 at 14:26









                                              Huseyin

                                              91721931




                                              91721931








                                              • 1




                                                I couldn't login as sudo mysql -u root but I was able to do it as sudo mysql and run the ALTER USER command.
                                                – itsols
                                                Oct 24 at 7:59






                                              • 1




                                                Life savior. Quick and clean.
                                                – Marcelo Agimóvel
                                                Nov 4 at 0:08














                                              • 1




                                                I couldn't login as sudo mysql -u root but I was able to do it as sudo mysql and run the ALTER USER command.
                                                – itsols
                                                Oct 24 at 7:59






                                              • 1




                                                Life savior. Quick and clean.
                                                – Marcelo Agimóvel
                                                Nov 4 at 0:08








                                              1




                                              1




                                              I couldn't login as sudo mysql -u root but I was able to do it as sudo mysql and run the ALTER USER command.
                                              – itsols
                                              Oct 24 at 7:59




                                              I couldn't login as sudo mysql -u root but I was able to do it as sudo mysql and run the ALTER USER command.
                                              – itsols
                                              Oct 24 at 7:59




                                              1




                                              1




                                              Life savior. Quick and clean.
                                              – Marcelo Agimóvel
                                              Nov 4 at 0:08




                                              Life savior. Quick and clean.
                                              – Marcelo Agimóvel
                                              Nov 4 at 0:08










                                              up vote
                                              6
                                              down vote













                                              Echoing rogerdpack's comment: if you don't know the MySQL root password and you don't care about MySQL data/settings, you can reinstall it and reset the root's password as follows:



                                              sudo apt-get remove --purge mysql-server mysql-client mysql-common
                                              sudo rm -rf /var/lib/mysql
                                              sudo apt-get install -y mysql-server mysql-client


                                              During the installation, you can choose the root's password:



                                              enter image description here






                                              share|improve this answer



















                                              • 1




                                                I wish I had started here instead of wasting an hour banging my head at trying to reset the password.
                                                – Eric Seastrand
                                                Sep 12 at 23:23















                                              up vote
                                              6
                                              down vote













                                              Echoing rogerdpack's comment: if you don't know the MySQL root password and you don't care about MySQL data/settings, you can reinstall it and reset the root's password as follows:



                                              sudo apt-get remove --purge mysql-server mysql-client mysql-common
                                              sudo rm -rf /var/lib/mysql
                                              sudo apt-get install -y mysql-server mysql-client


                                              During the installation, you can choose the root's password:



                                              enter image description here






                                              share|improve this answer



















                                              • 1




                                                I wish I had started here instead of wasting an hour banging my head at trying to reset the password.
                                                – Eric Seastrand
                                                Sep 12 at 23:23













                                              up vote
                                              6
                                              down vote










                                              up vote
                                              6
                                              down vote









                                              Echoing rogerdpack's comment: if you don't know the MySQL root password and you don't care about MySQL data/settings, you can reinstall it and reset the root's password as follows:



                                              sudo apt-get remove --purge mysql-server mysql-client mysql-common
                                              sudo rm -rf /var/lib/mysql
                                              sudo apt-get install -y mysql-server mysql-client


                                              During the installation, you can choose the root's password:



                                              enter image description here






                                              share|improve this answer














                                              Echoing rogerdpack's comment: if you don't know the MySQL root password and you don't care about MySQL data/settings, you can reinstall it and reset the root's password as follows:



                                              sudo apt-get remove --purge mysql-server mysql-client mysql-common
                                              sudo rm -rf /var/lib/mysql
                                              sudo apt-get install -y mysql-server mysql-client


                                              During the installation, you can choose the root's password:



                                              enter image description here







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Jan 27 at 1:36

























                                              answered Jan 22 at 22:39









                                              Franck Dernoncourt

                                              35.9k30191338




                                              35.9k30191338








                                              • 1




                                                I wish I had started here instead of wasting an hour banging my head at trying to reset the password.
                                                – Eric Seastrand
                                                Sep 12 at 23:23














                                              • 1




                                                I wish I had started here instead of wasting an hour banging my head at trying to reset the password.
                                                – Eric Seastrand
                                                Sep 12 at 23:23








                                              1




                                              1




                                              I wish I had started here instead of wasting an hour banging my head at trying to reset the password.
                                              – Eric Seastrand
                                              Sep 12 at 23:23




                                              I wish I had started here instead of wasting an hour banging my head at trying to reset the password.
                                              – Eric Seastrand
                                              Sep 12 at 23:23










                                              up vote
                                              3
                                              down vote













                                              If you know your current password, you don't have to stop mysql server.
                                              Open the ubuntu terminal.
                                              Login to mysql using:



                                              mysql - username -p


                                              Then type your password.
                                              This will take you into the mysql console.
                                              Inside the console, type:



                                              > ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';


                                              Then flush privileges using:



                                              > flush privileges;


                                              Then you are all done.






                                              share|improve this answer

























                                                up vote
                                                3
                                                down vote













                                                If you know your current password, you don't have to stop mysql server.
                                                Open the ubuntu terminal.
                                                Login to mysql using:



                                                mysql - username -p


                                                Then type your password.
                                                This will take you into the mysql console.
                                                Inside the console, type:



                                                > ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';


                                                Then flush privileges using:



                                                > flush privileges;


                                                Then you are all done.






                                                share|improve this answer























                                                  up vote
                                                  3
                                                  down vote










                                                  up vote
                                                  3
                                                  down vote









                                                  If you know your current password, you don't have to stop mysql server.
                                                  Open the ubuntu terminal.
                                                  Login to mysql using:



                                                  mysql - username -p


                                                  Then type your password.
                                                  This will take you into the mysql console.
                                                  Inside the console, type:



                                                  > ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';


                                                  Then flush privileges using:



                                                  > flush privileges;


                                                  Then you are all done.






                                                  share|improve this answer












                                                  If you know your current password, you don't have to stop mysql server.
                                                  Open the ubuntu terminal.
                                                  Login to mysql using:



                                                  mysql - username -p


                                                  Then type your password.
                                                  This will take you into the mysql console.
                                                  Inside the console, type:



                                                  > ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';


                                                  Then flush privileges using:



                                                  > flush privileges;


                                                  Then you are all done.







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Aug 24 '17 at 7:38









                                                  Peter Mutisya

                                                  11123




                                                  11123






















                                                      up vote
                                                      2
                                                      down vote













                                                      When you use MySQL's PASSWORD() on the system where you want to change the password, it can cause the password turn up in a MySQL log in cleartext [source]. Keeping them, their backups etc. as secure as the password sounds like nightmare to me, so I rather like to do it as follows:





                                                      1. On your local machine, run this with your password:



                                                         mysql -u someuser -p < <(echo "SELECT PASSWORD('mypass');")


                                                        Note the space in front to prevent it from turning up in the bash history (for other distros than Ubuntu, this might work differently – source).




                                                      2. On your server machine, execute the following command to change its MySQL root password (replace myhash with your password's hash as printed by the first command):



                                                        mysql -u root -p < <(echo "SET PASSWORD FOR root@localhost = 'myhash';")


                                                      3. Optionally, let's be a bit paranoid: On your local machine, clear your terminal screen with clear and purge your virtual terminal scrollback, to hide the cleartext password appearing in the command above.







                                                      share|improve this answer



























                                                        up vote
                                                        2
                                                        down vote













                                                        When you use MySQL's PASSWORD() on the system where you want to change the password, it can cause the password turn up in a MySQL log in cleartext [source]. Keeping them, their backups etc. as secure as the password sounds like nightmare to me, so I rather like to do it as follows:





                                                        1. On your local machine, run this with your password:



                                                           mysql -u someuser -p < <(echo "SELECT PASSWORD('mypass');")


                                                          Note the space in front to prevent it from turning up in the bash history (for other distros than Ubuntu, this might work differently – source).




                                                        2. On your server machine, execute the following command to change its MySQL root password (replace myhash with your password's hash as printed by the first command):



                                                          mysql -u root -p < <(echo "SET PASSWORD FOR root@localhost = 'myhash';")


                                                        3. Optionally, let's be a bit paranoid: On your local machine, clear your terminal screen with clear and purge your virtual terminal scrollback, to hide the cleartext password appearing in the command above.







                                                        share|improve this answer

























                                                          up vote
                                                          2
                                                          down vote










                                                          up vote
                                                          2
                                                          down vote









                                                          When you use MySQL's PASSWORD() on the system where you want to change the password, it can cause the password turn up in a MySQL log in cleartext [source]. Keeping them, their backups etc. as secure as the password sounds like nightmare to me, so I rather like to do it as follows:





                                                          1. On your local machine, run this with your password:



                                                             mysql -u someuser -p < <(echo "SELECT PASSWORD('mypass');")


                                                            Note the space in front to prevent it from turning up in the bash history (for other distros than Ubuntu, this might work differently – source).




                                                          2. On your server machine, execute the following command to change its MySQL root password (replace myhash with your password's hash as printed by the first command):



                                                            mysql -u root -p < <(echo "SET PASSWORD FOR root@localhost = 'myhash';")


                                                          3. Optionally, let's be a bit paranoid: On your local machine, clear your terminal screen with clear and purge your virtual terminal scrollback, to hide the cleartext password appearing in the command above.







                                                          share|improve this answer














                                                          When you use MySQL's PASSWORD() on the system where you want to change the password, it can cause the password turn up in a MySQL log in cleartext [source]. Keeping them, their backups etc. as secure as the password sounds like nightmare to me, so I rather like to do it as follows:





                                                          1. On your local machine, run this with your password:



                                                             mysql -u someuser -p < <(echo "SELECT PASSWORD('mypass');")


                                                            Note the space in front to prevent it from turning up in the bash history (for other distros than Ubuntu, this might work differently – source).




                                                          2. On your server machine, execute the following command to change its MySQL root password (replace myhash with your password's hash as printed by the first command):



                                                            mysql -u root -p < <(echo "SET PASSWORD FOR root@localhost = 'myhash';")


                                                          3. Optionally, let's be a bit paranoid: On your local machine, clear your terminal screen with clear and purge your virtual terminal scrollback, to hide the cleartext password appearing in the command above.








                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Apr 13 '17 at 12:36









                                                          Community

                                                          11




                                                          11










                                                          answered Mar 6 '14 at 17:48









                                                          tanius

                                                          3,11411826




                                                          3,11411826






















                                                              up vote
                                                              2
                                                              down vote













                                                              To update the "root" Mysql user password you must have in mind that you will need of super user permissions for that. If you have super user privilegies, try the following commands:



                                                              MySQL 5.7.6 and later



                                                              sudo su
                                                              service mysql stop
                                                              mysql -u root
                                                              ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
                                                              q;
                                                              exit
                                                              mysql -u root -p MyNewPass


                                                              MySQL 5.7.5 and earlier



                                                              sudo su
                                                              service mysql stop
                                                              mysql -u root
                                                              SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
                                                              q;
                                                              exit
                                                              mysql -u root -p MyNewPass





                                                              share|improve this answer

























                                                                up vote
                                                                2
                                                                down vote













                                                                To update the "root" Mysql user password you must have in mind that you will need of super user permissions for that. If you have super user privilegies, try the following commands:



                                                                MySQL 5.7.6 and later



                                                                sudo su
                                                                service mysql stop
                                                                mysql -u root
                                                                ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
                                                                q;
                                                                exit
                                                                mysql -u root -p MyNewPass


                                                                MySQL 5.7.5 and earlier



                                                                sudo su
                                                                service mysql stop
                                                                mysql -u root
                                                                SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
                                                                q;
                                                                exit
                                                                mysql -u root -p MyNewPass





                                                                share|improve this answer























                                                                  up vote
                                                                  2
                                                                  down vote










                                                                  up vote
                                                                  2
                                                                  down vote









                                                                  To update the "root" Mysql user password you must have in mind that you will need of super user permissions for that. If you have super user privilegies, try the following commands:



                                                                  MySQL 5.7.6 and later



                                                                  sudo su
                                                                  service mysql stop
                                                                  mysql -u root
                                                                  ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
                                                                  q;
                                                                  exit
                                                                  mysql -u root -p MyNewPass


                                                                  MySQL 5.7.5 and earlier



                                                                  sudo su
                                                                  service mysql stop
                                                                  mysql -u root
                                                                  SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
                                                                  q;
                                                                  exit
                                                                  mysql -u root -p MyNewPass





                                                                  share|improve this answer












                                                                  To update the "root" Mysql user password you must have in mind that you will need of super user permissions for that. If you have super user privilegies, try the following commands:



                                                                  MySQL 5.7.6 and later



                                                                  sudo su
                                                                  service mysql stop
                                                                  mysql -u root
                                                                  ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
                                                                  q;
                                                                  exit
                                                                  mysql -u root -p MyNewPass


                                                                  MySQL 5.7.5 and earlier



                                                                  sudo su
                                                                  service mysql stop
                                                                  mysql -u root
                                                                  SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
                                                                  q;
                                                                  exit
                                                                  mysql -u root -p MyNewPass






                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Feb 7 at 13:56









                                                                  alvaropaco

                                                                  655816




                                                                  655816






















                                                                      up vote
                                                                      1
                                                                      down vote













                                                                      Instead of resetting the password there is a work around on the local machine if you have setup phpmyadmin to connect without giving the password or username. Check this out by starting mysql, apache etc. I have xampp installed in my local machine. So starting the xampp will start all the necessary services. Now going to http://localhost/phpmyadmin shows me all the databases. This confirms that you have saved the username and passsword in the config file of phpmyadmin which can be found in the phpmyadmin install location. If you have xampp installed the phpmyadmin folder can be found in the root folder of xampp installation. Search for the word password in the config.inc.php file. There you will find the password and username.






                                                                      share|improve this answer

























                                                                        up vote
                                                                        1
                                                                        down vote













                                                                        Instead of resetting the password there is a work around on the local machine if you have setup phpmyadmin to connect without giving the password or username. Check this out by starting mysql, apache etc. I have xampp installed in my local machine. So starting the xampp will start all the necessary services. Now going to http://localhost/phpmyadmin shows me all the databases. This confirms that you have saved the username and passsword in the config file of phpmyadmin which can be found in the phpmyadmin install location. If you have xampp installed the phpmyadmin folder can be found in the root folder of xampp installation. Search for the word password in the config.inc.php file. There you will find the password and username.






                                                                        share|improve this answer























                                                                          up vote
                                                                          1
                                                                          down vote










                                                                          up vote
                                                                          1
                                                                          down vote









                                                                          Instead of resetting the password there is a work around on the local machine if you have setup phpmyadmin to connect without giving the password or username. Check this out by starting mysql, apache etc. I have xampp installed in my local machine. So starting the xampp will start all the necessary services. Now going to http://localhost/phpmyadmin shows me all the databases. This confirms that you have saved the username and passsword in the config file of phpmyadmin which can be found in the phpmyadmin install location. If you have xampp installed the phpmyadmin folder can be found in the root folder of xampp installation. Search for the word password in the config.inc.php file. There you will find the password and username.






                                                                          share|improve this answer












                                                                          Instead of resetting the password there is a work around on the local machine if you have setup phpmyadmin to connect without giving the password or username. Check this out by starting mysql, apache etc. I have xampp installed in my local machine. So starting the xampp will start all the necessary services. Now going to http://localhost/phpmyadmin shows me all the databases. This confirms that you have saved the username and passsword in the config file of phpmyadmin which can be found in the phpmyadmin install location. If you have xampp installed the phpmyadmin folder can be found in the root folder of xampp installation. Search for the word password in the config.inc.php file. There you will find the password and username.







                                                                          share|improve this answer












                                                                          share|improve this answer



                                                                          share|improve this answer










                                                                          answered Feb 25 '16 at 17:13









                                                                          joseph

                                                                          169111




                                                                          169111






















                                                                              up vote
                                                                              1
                                                                              down vote













                                                                              You can easily change the mysql password if deployed on xampp through provided phpadmin gui.



                                                                              phpMyAdmin -> User Accounts -> Edit Privileges (Select the intended user) -> Change Password (Tab)





                                                                              share|improve this answer

























                                                                                up vote
                                                                                1
                                                                                down vote













                                                                                You can easily change the mysql password if deployed on xampp through provided phpadmin gui.



                                                                                phpMyAdmin -> User Accounts -> Edit Privileges (Select the intended user) -> Change Password (Tab)





                                                                                share|improve this answer























                                                                                  up vote
                                                                                  1
                                                                                  down vote










                                                                                  up vote
                                                                                  1
                                                                                  down vote









                                                                                  You can easily change the mysql password if deployed on xampp through provided phpadmin gui.



                                                                                  phpMyAdmin -> User Accounts -> Edit Privileges (Select the intended user) -> Change Password (Tab)





                                                                                  share|improve this answer












                                                                                  You can easily change the mysql password if deployed on xampp through provided phpadmin gui.



                                                                                  phpMyAdmin -> User Accounts -> Edit Privileges (Select the intended user) -> Change Password (Tab)






                                                                                  share|improve this answer












                                                                                  share|improve this answer



                                                                                  share|improve this answer










                                                                                  answered Dec 21 '16 at 4:41









                                                                                  Mohd Arshil

                                                                                  100118




                                                                                  100118






















                                                                                      up vote
                                                                                      1
                                                                                      down vote













                                                                                      You can use this command :



                                                                                      UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';



                                                                                      after that pleas use flush
                                                                                      FLUSH PRIVILEGES;






                                                                                      share|improve this answer

























                                                                                        up vote
                                                                                        1
                                                                                        down vote













                                                                                        You can use this command :



                                                                                        UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';



                                                                                        after that pleas use flush
                                                                                        FLUSH PRIVILEGES;






                                                                                        share|improve this answer























                                                                                          up vote
                                                                                          1
                                                                                          down vote










                                                                                          up vote
                                                                                          1
                                                                                          down vote









                                                                                          You can use this command :



                                                                                          UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';



                                                                                          after that pleas use flush
                                                                                          FLUSH PRIVILEGES;






                                                                                          share|improve this answer












                                                                                          You can use this command :



                                                                                          UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';



                                                                                          after that pleas use flush
                                                                                          FLUSH PRIVILEGES;







                                                                                          share|improve this answer












                                                                                          share|improve this answer



                                                                                          share|improve this answer










                                                                                          answered Jan 2 '17 at 9:40









                                                                                          Rahul Karande

                                                                                          22529




                                                                                          22529






















                                                                                              up vote
                                                                                              1
                                                                                              down vote













                                                                                              for mysql 5.6 this command works and you can set password through the wizard:



                                                                                              sudo dpkg-reconfigure mysql-server-5.6





                                                                                              share|improve this answer





















                                                                                              • I tried but its not working.. I am getting this bellow error.. could you please help? This installation of MySQL is already upgraded to 5.7.21, use --force if you still need to run mysql_upgrade
                                                                                                – Vijaysinh Parmar
                                                                                                Mar 23 at 7:30















                                                                                              up vote
                                                                                              1
                                                                                              down vote













                                                                                              for mysql 5.6 this command works and you can set password through the wizard:



                                                                                              sudo dpkg-reconfigure mysql-server-5.6





                                                                                              share|improve this answer





















                                                                                              • I tried but its not working.. I am getting this bellow error.. could you please help? This installation of MySQL is already upgraded to 5.7.21, use --force if you still need to run mysql_upgrade
                                                                                                – Vijaysinh Parmar
                                                                                                Mar 23 at 7:30













                                                                                              up vote
                                                                                              1
                                                                                              down vote










                                                                                              up vote
                                                                                              1
                                                                                              down vote









                                                                                              for mysql 5.6 this command works and you can set password through the wizard:



                                                                                              sudo dpkg-reconfigure mysql-server-5.6





                                                                                              share|improve this answer












                                                                                              for mysql 5.6 this command works and you can set password through the wizard:



                                                                                              sudo dpkg-reconfigure mysql-server-5.6






                                                                                              share|improve this answer












                                                                                              share|improve this answer



                                                                                              share|improve this answer










                                                                                              answered May 9 '17 at 6:13









                                                                                              MSS

                                                                                              1,7571321




                                                                                              1,7571321












                                                                                              • I tried but its not working.. I am getting this bellow error.. could you please help? This installation of MySQL is already upgraded to 5.7.21, use --force if you still need to run mysql_upgrade
                                                                                                – Vijaysinh Parmar
                                                                                                Mar 23 at 7:30


















                                                                                              • I tried but its not working.. I am getting this bellow error.. could you please help? This installation of MySQL is already upgraded to 5.7.21, use --force if you still need to run mysql_upgrade
                                                                                                – Vijaysinh Parmar
                                                                                                Mar 23 at 7:30
















                                                                                              I tried but its not working.. I am getting this bellow error.. could you please help? This installation of MySQL is already upgraded to 5.7.21, use --force if you still need to run mysql_upgrade
                                                                                              – Vijaysinh Parmar
                                                                                              Mar 23 at 7:30




                                                                                              I tried but its not working.. I am getting this bellow error.. could you please help? This installation of MySQL is already upgraded to 5.7.21, use --force if you still need to run mysql_upgrade
                                                                                              – Vijaysinh Parmar
                                                                                              Mar 23 at 7:30










                                                                                              up vote
                                                                                              1
                                                                                              down vote













                                                                                              You don't need all this. Simply log in:



                                                                                              mysql -u root -p



                                                                                              Then change the current user's password as the mysql> prompt:



                                                                                              mysql> set password=password('the_new_password');
                                                                                              mysql> flush privileges;





                                                                                              share|improve this answer

























                                                                                                up vote
                                                                                                1
                                                                                                down vote













                                                                                                You don't need all this. Simply log in:



                                                                                                mysql -u root -p



                                                                                                Then change the current user's password as the mysql> prompt:



                                                                                                mysql> set password=password('the_new_password');
                                                                                                mysql> flush privileges;





                                                                                                share|improve this answer























                                                                                                  up vote
                                                                                                  1
                                                                                                  down vote










                                                                                                  up vote
                                                                                                  1
                                                                                                  down vote









                                                                                                  You don't need all this. Simply log in:



                                                                                                  mysql -u root -p



                                                                                                  Then change the current user's password as the mysql> prompt:



                                                                                                  mysql> set password=password('the_new_password');
                                                                                                  mysql> flush privileges;





                                                                                                  share|improve this answer












                                                                                                  You don't need all this. Simply log in:



                                                                                                  mysql -u root -p



                                                                                                  Then change the current user's password as the mysql> prompt:



                                                                                                  mysql> set password=password('the_new_password');
                                                                                                  mysql> flush privileges;






                                                                                                  share|improve this answer












                                                                                                  share|improve this answer



                                                                                                  share|improve this answer










                                                                                                  answered Mar 11 at 18:09









                                                                                                  mprivat

                                                                                                  17.8k44057




                                                                                                  17.8k44057






















                                                                                                      up vote
                                                                                                      1
                                                                                                      down vote













                                                                                                      You can try these some steps to reset mysql 5.7 root password :



                                                                                                      Stop Mysql Service 1st



                                                                                                      sudo /etc/init.d/mysql stop 


                                                                                                      Login as root without password
                                                                                                      sudo mysqld_safe --skip-grant-tables &



                                                                                                      After login mysql terminal you should need execute commands more:



                                                                                                      use mysql;




                                                                                                      UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root';


                                                                                                      flush privileges;


                                                                                                      sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                                                                                      After you restart your mysql server
                                                                                                      If you still facing error you must visit :
                                                                                                      Reset MySQL 5.7 root password Ubuntu 16.04






                                                                                                      share|improve this answer



























                                                                                                        up vote
                                                                                                        1
                                                                                                        down vote













                                                                                                        You can try these some steps to reset mysql 5.7 root password :



                                                                                                        Stop Mysql Service 1st



                                                                                                        sudo /etc/init.d/mysql stop 


                                                                                                        Login as root without password
                                                                                                        sudo mysqld_safe --skip-grant-tables &



                                                                                                        After login mysql terminal you should need execute commands more:



                                                                                                        use mysql;




                                                                                                        UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root';


                                                                                                        flush privileges;


                                                                                                        sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                                                                                        After you restart your mysql server
                                                                                                        If you still facing error you must visit :
                                                                                                        Reset MySQL 5.7 root password Ubuntu 16.04






                                                                                                        share|improve this answer

























                                                                                                          up vote
                                                                                                          1
                                                                                                          down vote










                                                                                                          up vote
                                                                                                          1
                                                                                                          down vote









                                                                                                          You can try these some steps to reset mysql 5.7 root password :



                                                                                                          Stop Mysql Service 1st



                                                                                                          sudo /etc/init.d/mysql stop 


                                                                                                          Login as root without password
                                                                                                          sudo mysqld_safe --skip-grant-tables &



                                                                                                          After login mysql terminal you should need execute commands more:



                                                                                                          use mysql;




                                                                                                          UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root';


                                                                                                          flush privileges;


                                                                                                          sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                                                                                          After you restart your mysql server
                                                                                                          If you still facing error you must visit :
                                                                                                          Reset MySQL 5.7 root password Ubuntu 16.04






                                                                                                          share|improve this answer














                                                                                                          You can try these some steps to reset mysql 5.7 root password :



                                                                                                          Stop Mysql Service 1st



                                                                                                          sudo /etc/init.d/mysql stop 


                                                                                                          Login as root without password
                                                                                                          sudo mysqld_safe --skip-grant-tables &



                                                                                                          After login mysql terminal you should need execute commands more:



                                                                                                          use mysql;




                                                                                                          UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root';


                                                                                                          flush privileges;


                                                                                                          sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown


                                                                                                          After you restart your mysql server
                                                                                                          If you still facing error you must visit :
                                                                                                          Reset MySQL 5.7 root password Ubuntu 16.04







                                                                                                          share|improve this answer














                                                                                                          share|improve this answer



                                                                                                          share|improve this answer








                                                                                                          edited Mar 21 at 9:06









                                                                                                          Amitesh Kumar

                                                                                                          2,1321732




                                                                                                          2,1321732










                                                                                                          answered Mar 21 at 8:27









                                                                                                          Inderpal Singh

                                                                                                          9111




                                                                                                          9111






















                                                                                                              up vote
                                                                                                              1
                                                                                                              down vote













                                                                                                              This is the solution for me. I work at Ubuntu 18.04:
                                                                                                              https://stackoverflow.com/a/46076838/2400373



                                                                                                              But is important this change in the last step:



                                                                                                              UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost'; 





                                                                                                              share|improve this answer

























                                                                                                                up vote
                                                                                                                1
                                                                                                                down vote













                                                                                                                This is the solution for me. I work at Ubuntu 18.04:
                                                                                                                https://stackoverflow.com/a/46076838/2400373



                                                                                                                But is important this change in the last step:



                                                                                                                UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost'; 





                                                                                                                share|improve this answer























                                                                                                                  up vote
                                                                                                                  1
                                                                                                                  down vote










                                                                                                                  up vote
                                                                                                                  1
                                                                                                                  down vote









                                                                                                                  This is the solution for me. I work at Ubuntu 18.04:
                                                                                                                  https://stackoverflow.com/a/46076838/2400373



                                                                                                                  But is important this change in the last step:



                                                                                                                  UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost'; 





                                                                                                                  share|improve this answer












                                                                                                                  This is the solution for me. I work at Ubuntu 18.04:
                                                                                                                  https://stackoverflow.com/a/46076838/2400373



                                                                                                                  But is important this change in the last step:



                                                                                                                  UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost'; 






                                                                                                                  share|improve this answer












                                                                                                                  share|improve this answer



                                                                                                                  share|improve this answer










                                                                                                                  answered Nov 20 at 3:22









                                                                                                                  juanitourquiza

                                                                                                                  357518




                                                                                                                  357518






















                                                                                                                      up vote
                                                                                                                      0
                                                                                                                      down vote













                                                                                                                      when changing/resetting the MySQL password the following commands listed above did not help. I found that going into the terminal and using these commands is pointless. instead use the command sudo stop everything. DELETE SYSTEM 32 for windows if that helps.






                                                                                                                      share|improve this answer

















                                                                                                                      • 1




                                                                                                                        The question is about ubuntu OS not windows. What do you mean by DELETE SYSTEM 32 for windows?
                                                                                                                        – EhsanT
                                                                                                                        Jan 14 '17 at 2:13















                                                                                                                      up vote
                                                                                                                      0
                                                                                                                      down vote













                                                                                                                      when changing/resetting the MySQL password the following commands listed above did not help. I found that going into the terminal and using these commands is pointless. instead use the command sudo stop everything. DELETE SYSTEM 32 for windows if that helps.






                                                                                                                      share|improve this answer

















                                                                                                                      • 1




                                                                                                                        The question is about ubuntu OS not windows. What do you mean by DELETE SYSTEM 32 for windows?
                                                                                                                        – EhsanT
                                                                                                                        Jan 14 '17 at 2:13













                                                                                                                      up vote
                                                                                                                      0
                                                                                                                      down vote










                                                                                                                      up vote
                                                                                                                      0
                                                                                                                      down vote









                                                                                                                      when changing/resetting the MySQL password the following commands listed above did not help. I found that going into the terminal and using these commands is pointless. instead use the command sudo stop everything. DELETE SYSTEM 32 for windows if that helps.






                                                                                                                      share|improve this answer












                                                                                                                      when changing/resetting the MySQL password the following commands listed above did not help. I found that going into the terminal and using these commands is pointless. instead use the command sudo stop everything. DELETE SYSTEM 32 for windows if that helps.







                                                                                                                      share|improve this answer












                                                                                                                      share|improve this answer



                                                                                                                      share|improve this answer










                                                                                                                      answered Jan 14 '17 at 2:08









                                                                                                                      Rock

                                                                                                                      19




                                                                                                                      19








                                                                                                                      • 1




                                                                                                                        The question is about ubuntu OS not windows. What do you mean by DELETE SYSTEM 32 for windows?
                                                                                                                        – EhsanT
                                                                                                                        Jan 14 '17 at 2:13














                                                                                                                      • 1




                                                                                                                        The question is about ubuntu OS not windows. What do you mean by DELETE SYSTEM 32 for windows?
                                                                                                                        – EhsanT
                                                                                                                        Jan 14 '17 at 2:13








                                                                                                                      1




                                                                                                                      1




                                                                                                                      The question is about ubuntu OS not windows. What do you mean by DELETE SYSTEM 32 for windows?
                                                                                                                      – EhsanT
                                                                                                                      Jan 14 '17 at 2:13




                                                                                                                      The question is about ubuntu OS not windows. What do you mean by DELETE SYSTEM 32 for windows?
                                                                                                                      – EhsanT
                                                                                                                      Jan 14 '17 at 2:13










                                                                                                                      up vote
                                                                                                                      0
                                                                                                                      down vote













                                                                                                                      To reset or change the password enter sudo dpkg-reconfigure mysql-server-X.X (X.X is mysql version you have installed i.e. 5.6, 5.7) and then you will prompt a screen where you have to set the new password and then in next step confirm the password and just wait for a moment. That's it.






                                                                                                                      share|improve this answer

























                                                                                                                        up vote
                                                                                                                        0
                                                                                                                        down vote













                                                                                                                        To reset or change the password enter sudo dpkg-reconfigure mysql-server-X.X (X.X is mysql version you have installed i.e. 5.6, 5.7) and then you will prompt a screen where you have to set the new password and then in next step confirm the password and just wait for a moment. That's it.






                                                                                                                        share|improve this answer























                                                                                                                          up vote
                                                                                                                          0
                                                                                                                          down vote










                                                                                                                          up vote
                                                                                                                          0
                                                                                                                          down vote









                                                                                                                          To reset or change the password enter sudo dpkg-reconfigure mysql-server-X.X (X.X is mysql version you have installed i.e. 5.6, 5.7) and then you will prompt a screen where you have to set the new password and then in next step confirm the password and just wait for a moment. That's it.






                                                                                                                          share|improve this answer












                                                                                                                          To reset or change the password enter sudo dpkg-reconfigure mysql-server-X.X (X.X is mysql version you have installed i.e. 5.6, 5.7) and then you will prompt a screen where you have to set the new password and then in next step confirm the password and just wait for a moment. That's it.







                                                                                                                          share|improve this answer












                                                                                                                          share|improve this answer



                                                                                                                          share|improve this answer










                                                                                                                          answered Jan 22 at 11:23









                                                                                                                          Gaurav Paliwal

                                                                                                                          675619




                                                                                                                          675619






















                                                                                                                              up vote
                                                                                                                              0
                                                                                                                              down vote













                                                                                                                              I had to go this route on Ubuntu 16.04.1 LTS. It is somewhat of a mix of some of the other answers above - but none of them helped. I spent an hour or more trying all other suggestions from MySql website to everything on SO, I finally got it working with:


                                                                                                                              Note: while it showed Enter password for user root, I didnt have the original password so I just entered the same password to be used as the new password.


                                                                                                                              Note: there was no /var/log/mysqld.log only /var/log/mysql/error.log



                                                                                                                              Also note this did not work for me:

                                                                                                                              sudo dpkg-reconfigure mysql-server-5.7



                                                                                                                              Nor did:

                                                                                                                              sudo dpkg-reconfigure --force mysql-server-5.5



                                                                                                                              Make MySQL service directory.

                                                                                                                              sudo mkdir /var/run/mysqld



                                                                                                                              Give MySQL user permission to write to the service directory.

                                                                                                                              sudo chown mysql: /var/run/mysqld



                                                                                                                              Then:




                                                                                                                              1. kill the current mysqld pid

                                                                                                                              2. run mysqld with sudo /usr/sbin/mysqld &


                                                                                                                              3. run /usr/bin/mysql_secure_installation


                                                                                                                                Output from mysql_secure_installation




                                                                                                                                root@myServer:~# /usr/bin/mysql_secure_installation



                                                                                                                                Securing the MySQL server deployment.



                                                                                                                                Enter password for user root:



                                                                                                                                VALIDATE PASSWORD PLUGIN can be used to test passwords
                                                                                                                                and improve security. It checks the strength of password
                                                                                                                                and allows the users to set only those passwords which are
                                                                                                                                secure enough. Would you like to setup VALIDATE PASSWORD plugin?



                                                                                                                                Press y|Y for Yes, any other key for No: no
                                                                                                                                Using existing password for root.
                                                                                                                                Change the password for root ? ((Press y|Y for Yes, any other key for No) : y



                                                                                                                                New password:



                                                                                                                                Re-enter new password:
                                                                                                                                By default, a MySQL installation has an anonymous user,
                                                                                                                                allowing anyone to log into MySQL without having to have
                                                                                                                                a user account created for them. This is intended only for
                                                                                                                                testing, and to make the installation go a bit smoother.
                                                                                                                                You should remove them before moving into a production
                                                                                                                                environment.



                                                                                                                                Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
                                                                                                                                Success.



                                                                                                                                Normally, root should only be allowed to connect from
                                                                                                                                'localhost'. This ensures that someone cannot guess at
                                                                                                                                the root password from the network.



                                                                                                                                Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
                                                                                                                                Success.



                                                                                                                                By default, MySQL comes with a database named 'test' that
                                                                                                                                anyone can access. This is also intended only for testing,
                                                                                                                                and should be removed before moving into a production
                                                                                                                                environment.



                                                                                                                                Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y




                                                                                                                                • Dropping test database...
                                                                                                                                  Success.


                                                                                                                                • Removing privileges on test database...
                                                                                                                                  Success.



                                                                                                                                Reloading the privilege tables will ensure that all changes
                                                                                                                                made so far will take effect immediately.



                                                                                                                                Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
                                                                                                                                Success.



                                                                                                                                All done!









                                                                                                                              share|improve this answer

























                                                                                                                                up vote
                                                                                                                                0
                                                                                                                                down vote













                                                                                                                                I had to go this route on Ubuntu 16.04.1 LTS. It is somewhat of a mix of some of the other answers above - but none of them helped. I spent an hour or more trying all other suggestions from MySql website to everything on SO, I finally got it working with:


                                                                                                                                Note: while it showed Enter password for user root, I didnt have the original password so I just entered the same password to be used as the new password.


                                                                                                                                Note: there was no /var/log/mysqld.log only /var/log/mysql/error.log



                                                                                                                                Also note this did not work for me:

                                                                                                                                sudo dpkg-reconfigure mysql-server-5.7



                                                                                                                                Nor did:

                                                                                                                                sudo dpkg-reconfigure --force mysql-server-5.5



                                                                                                                                Make MySQL service directory.

                                                                                                                                sudo mkdir /var/run/mysqld



                                                                                                                                Give MySQL user permission to write to the service directory.

                                                                                                                                sudo chown mysql: /var/run/mysqld



                                                                                                                                Then:




                                                                                                                                1. kill the current mysqld pid

                                                                                                                                2. run mysqld with sudo /usr/sbin/mysqld &


                                                                                                                                3. run /usr/bin/mysql_secure_installation


                                                                                                                                  Output from mysql_secure_installation




                                                                                                                                  root@myServer:~# /usr/bin/mysql_secure_installation



                                                                                                                                  Securing the MySQL server deployment.



                                                                                                                                  Enter password for user root:



                                                                                                                                  VALIDATE PASSWORD PLUGIN can be used to test passwords
                                                                                                                                  and improve security. It checks the strength of password
                                                                                                                                  and allows the users to set only those passwords which are
                                                                                                                                  secure enough. Would you like to setup VALIDATE PASSWORD plugin?



                                                                                                                                  Press y|Y for Yes, any other key for No: no
                                                                                                                                  Using existing password for root.
                                                                                                                                  Change the password for root ? ((Press y|Y for Yes, any other key for No) : y



                                                                                                                                  New password:



                                                                                                                                  Re-enter new password:
                                                                                                                                  By default, a MySQL installation has an anonymous user,
                                                                                                                                  allowing anyone to log into MySQL without having to have
                                                                                                                                  a user account created for them. This is intended only for
                                                                                                                                  testing, and to make the installation go a bit smoother.
                                                                                                                                  You should remove them before moving into a production
                                                                                                                                  environment.



                                                                                                                                  Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
                                                                                                                                  Success.



                                                                                                                                  Normally, root should only be allowed to connect from
                                                                                                                                  'localhost'. This ensures that someone cannot guess at
                                                                                                                                  the root password from the network.



                                                                                                                                  Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
                                                                                                                                  Success.



                                                                                                                                  By default, MySQL comes with a database named 'test' that
                                                                                                                                  anyone can access. This is also intended only for testing,
                                                                                                                                  and should be removed before moving into a production
                                                                                                                                  environment.



                                                                                                                                  Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y




                                                                                                                                  • Dropping test database...
                                                                                                                                    Success.


                                                                                                                                  • Removing privileges on test database...
                                                                                                                                    Success.



                                                                                                                                  Reloading the privilege tables will ensure that all changes
                                                                                                                                  made so far will take effect immediately.



                                                                                                                                  Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
                                                                                                                                  Success.



                                                                                                                                  All done!









                                                                                                                                share|improve this answer























                                                                                                                                  up vote
                                                                                                                                  0
                                                                                                                                  down vote










                                                                                                                                  up vote
                                                                                                                                  0
                                                                                                                                  down vote









                                                                                                                                  I had to go this route on Ubuntu 16.04.1 LTS. It is somewhat of a mix of some of the other answers above - but none of them helped. I spent an hour or more trying all other suggestions from MySql website to everything on SO, I finally got it working with:


                                                                                                                                  Note: while it showed Enter password for user root, I didnt have the original password so I just entered the same password to be used as the new password.


                                                                                                                                  Note: there was no /var/log/mysqld.log only /var/log/mysql/error.log



                                                                                                                                  Also note this did not work for me:

                                                                                                                                  sudo dpkg-reconfigure mysql-server-5.7



                                                                                                                                  Nor did:

                                                                                                                                  sudo dpkg-reconfigure --force mysql-server-5.5



                                                                                                                                  Make MySQL service directory.

                                                                                                                                  sudo mkdir /var/run/mysqld



                                                                                                                                  Give MySQL user permission to write to the service directory.

                                                                                                                                  sudo chown mysql: /var/run/mysqld



                                                                                                                                  Then:




                                                                                                                                  1. kill the current mysqld pid

                                                                                                                                  2. run mysqld with sudo /usr/sbin/mysqld &


                                                                                                                                  3. run /usr/bin/mysql_secure_installation


                                                                                                                                    Output from mysql_secure_installation




                                                                                                                                    root@myServer:~# /usr/bin/mysql_secure_installation



                                                                                                                                    Securing the MySQL server deployment.



                                                                                                                                    Enter password for user root:



                                                                                                                                    VALIDATE PASSWORD PLUGIN can be used to test passwords
                                                                                                                                    and improve security. It checks the strength of password
                                                                                                                                    and allows the users to set only those passwords which are
                                                                                                                                    secure enough. Would you like to setup VALIDATE PASSWORD plugin?



                                                                                                                                    Press y|Y for Yes, any other key for No: no
                                                                                                                                    Using existing password for root.
                                                                                                                                    Change the password for root ? ((Press y|Y for Yes, any other key for No) : y



                                                                                                                                    New password:



                                                                                                                                    Re-enter new password:
                                                                                                                                    By default, a MySQL installation has an anonymous user,
                                                                                                                                    allowing anyone to log into MySQL without having to have
                                                                                                                                    a user account created for them. This is intended only for
                                                                                                                                    testing, and to make the installation go a bit smoother.
                                                                                                                                    You should remove them before moving into a production
                                                                                                                                    environment.



                                                                                                                                    Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
                                                                                                                                    Success.



                                                                                                                                    Normally, root should only be allowed to connect from
                                                                                                                                    'localhost'. This ensures that someone cannot guess at
                                                                                                                                    the root password from the network.



                                                                                                                                    Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
                                                                                                                                    Success.



                                                                                                                                    By default, MySQL comes with a database named 'test' that
                                                                                                                                    anyone can access. This is also intended only for testing,
                                                                                                                                    and should be removed before moving into a production
                                                                                                                                    environment.



                                                                                                                                    Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y




                                                                                                                                    • Dropping test database...
                                                                                                                                      Success.


                                                                                                                                    • Removing privileges on test database...
                                                                                                                                      Success.



                                                                                                                                    Reloading the privilege tables will ensure that all changes
                                                                                                                                    made so far will take effect immediately.



                                                                                                                                    Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
                                                                                                                                    Success.



                                                                                                                                    All done!









                                                                                                                                  share|improve this answer












                                                                                                                                  I had to go this route on Ubuntu 16.04.1 LTS. It is somewhat of a mix of some of the other answers above - but none of them helped. I spent an hour or more trying all other suggestions from MySql website to everything on SO, I finally got it working with:


                                                                                                                                  Note: while it showed Enter password for user root, I didnt have the original password so I just entered the same password to be used as the new password.


                                                                                                                                  Note: there was no /var/log/mysqld.log only /var/log/mysql/error.log



                                                                                                                                  Also note this did not work for me:

                                                                                                                                  sudo dpkg-reconfigure mysql-server-5.7



                                                                                                                                  Nor did:

                                                                                                                                  sudo dpkg-reconfigure --force mysql-server-5.5



                                                                                                                                  Make MySQL service directory.

                                                                                                                                  sudo mkdir /var/run/mysqld



                                                                                                                                  Give MySQL user permission to write to the service directory.

                                                                                                                                  sudo chown mysql: /var/run/mysqld



                                                                                                                                  Then:




                                                                                                                                  1. kill the current mysqld pid

                                                                                                                                  2. run mysqld with sudo /usr/sbin/mysqld &


                                                                                                                                  3. run /usr/bin/mysql_secure_installation


                                                                                                                                    Output from mysql_secure_installation




                                                                                                                                    root@myServer:~# /usr/bin/mysql_secure_installation



                                                                                                                                    Securing the MySQL server deployment.



                                                                                                                                    Enter password for user root:



                                                                                                                                    VALIDATE PASSWORD PLUGIN can be used to test passwords
                                                                                                                                    and improve security. It checks the strength of password
                                                                                                                                    and allows the users to set only those passwords which are
                                                                                                                                    secure enough. Would you like to setup VALIDATE PASSWORD plugin?



                                                                                                                                    Press y|Y for Yes, any other key for No: no
                                                                                                                                    Using existing password for root.
                                                                                                                                    Change the password for root ? ((Press y|Y for Yes, any other key for No) : y



                                                                                                                                    New password:



                                                                                                                                    Re-enter new password:
                                                                                                                                    By default, a MySQL installation has an anonymous user,
                                                                                                                                    allowing anyone to log into MySQL without having to have
                                                                                                                                    a user account created for them. This is intended only for
                                                                                                                                    testing, and to make the installation go a bit smoother.
                                                                                                                                    You should remove them before moving into a production
                                                                                                                                    environment.



                                                                                                                                    Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
                                                                                                                                    Success.



                                                                                                                                    Normally, root should only be allowed to connect from
                                                                                                                                    'localhost'. This ensures that someone cannot guess at
                                                                                                                                    the root password from the network.



                                                                                                                                    Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
                                                                                                                                    Success.



                                                                                                                                    By default, MySQL comes with a database named 'test' that
                                                                                                                                    anyone can access. This is also intended only for testing,
                                                                                                                                    and should be removed before moving into a production
                                                                                                                                    environment.



                                                                                                                                    Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y




                                                                                                                                    • Dropping test database...
                                                                                                                                      Success.


                                                                                                                                    • Removing privileges on test database...
                                                                                                                                      Success.



                                                                                                                                    Reloading the privilege tables will ensure that all changes
                                                                                                                                    made so far will take effect immediately.



                                                                                                                                    Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
                                                                                                                                    Success.



                                                                                                                                    All done!










                                                                                                                                  share|improve this answer












                                                                                                                                  share|improve this answer



                                                                                                                                  share|improve this answer










                                                                                                                                  answered Feb 4 at 0:13









                                                                                                                                  JGlass

                                                                                                                                  9492620




                                                                                                                                  9492620






















                                                                                                                                      up vote
                                                                                                                                      0
                                                                                                                                      down vote













                                                                                                                                      As mysql documentation on the password() function says:




                                                                                                                                      This function was removed in MySQL 8.0.11.




                                                                                                                                      This invalidates pretty much all existing answers for mysql v8.0.11 and newer.



                                                                                                                                      Per mysql documentation the new generic way to reset the root password is as follows:




                                                                                                                                      The preceding sections provide password-resetting instructions
                                                                                                                                      specifically for Windows and Unix and Unix-like systems.
                                                                                                                                      Alternatively, on any platform, you can reset the password using the
                                                                                                                                      mysql client (but this approach is less secure):



                                                                                                                                      Stop the MySQL server if necessary, then restart it with the
                                                                                                                                      --skip-grant-tables option. This enables anyone to connect without a password and with all privileges, and disables account-management
                                                                                                                                      statements such as ALTER USER and SET PASSWORD. Because this is
                                                                                                                                      insecure, if the server is started with the --skip-grant-tables
                                                                                                                                      option, it enables --skip-networking automatically to prevent remote
                                                                                                                                      connections.



                                                                                                                                      Connect to the MySQL server using the mysql client; no password is
                                                                                                                                      necessary because the server was started with --skip-grant-tables:



                                                                                                                                      shell> mysql


                                                                                                                                      In the mysql client, tell the server to reload the grant tables so that account-management statements work:



                                                                                                                                      mysql> FLUSH PRIVILEGES;


                                                                                                                                      Then change the 'root'@'localhost' account password. Replace the password with the password that you want to use.
                                                                                                                                      To change the password for a root account with a different host name
                                                                                                                                      part, modify the instructions to use that host name.



                                                                                                                                      mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';


                                                                                                                                      You should now be able to connect to the MySQL server as root using the
                                                                                                                                      new password. Stop the server and restart it normally (without the
                                                                                                                                      --skip-grant-tables and --skip-networking options).







                                                                                                                                      share|improve this answer

























                                                                                                                                        up vote
                                                                                                                                        0
                                                                                                                                        down vote













                                                                                                                                        As mysql documentation on the password() function says:




                                                                                                                                        This function was removed in MySQL 8.0.11.




                                                                                                                                        This invalidates pretty much all existing answers for mysql v8.0.11 and newer.



                                                                                                                                        Per mysql documentation the new generic way to reset the root password is as follows:




                                                                                                                                        The preceding sections provide password-resetting instructions
                                                                                                                                        specifically for Windows and Unix and Unix-like systems.
                                                                                                                                        Alternatively, on any platform, you can reset the password using the
                                                                                                                                        mysql client (but this approach is less secure):



                                                                                                                                        Stop the MySQL server if necessary, then restart it with the
                                                                                                                                        --skip-grant-tables option. This enables anyone to connect without a password and with all privileges, and disables account-management
                                                                                                                                        statements such as ALTER USER and SET PASSWORD. Because this is
                                                                                                                                        insecure, if the server is started with the --skip-grant-tables
                                                                                                                                        option, it enables --skip-networking automatically to prevent remote
                                                                                                                                        connections.



                                                                                                                                        Connect to the MySQL server using the mysql client; no password is
                                                                                                                                        necessary because the server was started with --skip-grant-tables:



                                                                                                                                        shell> mysql


                                                                                                                                        In the mysql client, tell the server to reload the grant tables so that account-management statements work:



                                                                                                                                        mysql> FLUSH PRIVILEGES;


                                                                                                                                        Then change the 'root'@'localhost' account password. Replace the password with the password that you want to use.
                                                                                                                                        To change the password for a root account with a different host name
                                                                                                                                        part, modify the instructions to use that host name.



                                                                                                                                        mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';


                                                                                                                                        You should now be able to connect to the MySQL server as root using the
                                                                                                                                        new password. Stop the server and restart it normally (without the
                                                                                                                                        --skip-grant-tables and --skip-networking options).







                                                                                                                                        share|improve this answer























                                                                                                                                          up vote
                                                                                                                                          0
                                                                                                                                          down vote










                                                                                                                                          up vote
                                                                                                                                          0
                                                                                                                                          down vote









                                                                                                                                          As mysql documentation on the password() function says:




                                                                                                                                          This function was removed in MySQL 8.0.11.




                                                                                                                                          This invalidates pretty much all existing answers for mysql v8.0.11 and newer.



                                                                                                                                          Per mysql documentation the new generic way to reset the root password is as follows:




                                                                                                                                          The preceding sections provide password-resetting instructions
                                                                                                                                          specifically for Windows and Unix and Unix-like systems.
                                                                                                                                          Alternatively, on any platform, you can reset the password using the
                                                                                                                                          mysql client (but this approach is less secure):



                                                                                                                                          Stop the MySQL server if necessary, then restart it with the
                                                                                                                                          --skip-grant-tables option. This enables anyone to connect without a password and with all privileges, and disables account-management
                                                                                                                                          statements such as ALTER USER and SET PASSWORD. Because this is
                                                                                                                                          insecure, if the server is started with the --skip-grant-tables
                                                                                                                                          option, it enables --skip-networking automatically to prevent remote
                                                                                                                                          connections.



                                                                                                                                          Connect to the MySQL server using the mysql client; no password is
                                                                                                                                          necessary because the server was started with --skip-grant-tables:



                                                                                                                                          shell> mysql


                                                                                                                                          In the mysql client, tell the server to reload the grant tables so that account-management statements work:



                                                                                                                                          mysql> FLUSH PRIVILEGES;


                                                                                                                                          Then change the 'root'@'localhost' account password. Replace the password with the password that you want to use.
                                                                                                                                          To change the password for a root account with a different host name
                                                                                                                                          part, modify the instructions to use that host name.



                                                                                                                                          mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';


                                                                                                                                          You should now be able to connect to the MySQL server as root using the
                                                                                                                                          new password. Stop the server and restart it normally (without the
                                                                                                                                          --skip-grant-tables and --skip-networking options).







                                                                                                                                          share|improve this answer












                                                                                                                                          As mysql documentation on the password() function says:




                                                                                                                                          This function was removed in MySQL 8.0.11.




                                                                                                                                          This invalidates pretty much all existing answers for mysql v8.0.11 and newer.



                                                                                                                                          Per mysql documentation the new generic way to reset the root password is as follows:




                                                                                                                                          The preceding sections provide password-resetting instructions
                                                                                                                                          specifically for Windows and Unix and Unix-like systems.
                                                                                                                                          Alternatively, on any platform, you can reset the password using the
                                                                                                                                          mysql client (but this approach is less secure):



                                                                                                                                          Stop the MySQL server if necessary, then restart it with the
                                                                                                                                          --skip-grant-tables option. This enables anyone to connect without a password and with all privileges, and disables account-management
                                                                                                                                          statements such as ALTER USER and SET PASSWORD. Because this is
                                                                                                                                          insecure, if the server is started with the --skip-grant-tables
                                                                                                                                          option, it enables --skip-networking automatically to prevent remote
                                                                                                                                          connections.



                                                                                                                                          Connect to the MySQL server using the mysql client; no password is
                                                                                                                                          necessary because the server was started with --skip-grant-tables:



                                                                                                                                          shell> mysql


                                                                                                                                          In the mysql client, tell the server to reload the grant tables so that account-management statements work:



                                                                                                                                          mysql> FLUSH PRIVILEGES;


                                                                                                                                          Then change the 'root'@'localhost' account password. Replace the password with the password that you want to use.
                                                                                                                                          To change the password for a root account with a different host name
                                                                                                                                          part, modify the instructions to use that host name.



                                                                                                                                          mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';


                                                                                                                                          You should now be able to connect to the MySQL server as root using the
                                                                                                                                          new password. Stop the server and restart it normally (without the
                                                                                                                                          --skip-grant-tables and --skip-networking options).








                                                                                                                                          share|improve this answer












                                                                                                                                          share|improve this answer



                                                                                                                                          share|improve this answer










                                                                                                                                          answered Oct 28 at 10:52









                                                                                                                                          Shadow

                                                                                                                                          25.4k92742




                                                                                                                                          25.4k92742






























                                                                                                                                              draft saved

                                                                                                                                              draft discarded




















































                                                                                                                                              Thanks for contributing an answer to Stack Overflow!


                                                                                                                                              • 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%2fstackoverflow.com%2fquestions%2f16556497%2fhow-to-reset-or-change-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

                                                                                                                                              Tonle Sap (See)

                                                                                                                                              I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

                                                                                                                                              Guatemaltekische Davis-Cup-Mannschaft