Home > MySQL, ubuntu > MySQL: Error 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

MySQL: Error 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

I’ve upgraded MySQL server version to 5.1.54-1ubuntu4 and when I try to connect to the database I’m getting this error:

$ mysql -u root

Error 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Maybe updating the package the updater overwrote the root password.

To restore it:

  • Stop mysqld deamons.
$ sudo service mysql stop
  • Go  to  mysql/bin directory
$ cd /usr/bin
  • Start a mysql deamon with this option:
$ sudo mysqld_safe --skip-grant-tables
  • Open another terminal and open a mysql session to execute this:
$ mysql
mysql> use mysql;
mysql> UPDATE user SET password=PASSWORD('YOUR_NEW_PASSWORD_HERE') WHERE user = 'root';
mysql> exit;
  • Now kill the mysqld_safe process and restart mysqld normally:
$ sudo service mysql start
Categories: MySQL, ubuntu Tags: , , , ,
  1. navr
    December 5, 2015 at 1:03

    it did not work. I still have the same error:

    ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

    I did the exact steps as described

    Liked by 1 person

    • December 5, 2015 at 9:18

      Try “mysql -u root -p”
      You’ll be prompted for the root password you typed in the update statement.


  2. September 25, 2015 at 11:51

    Thank you for your guide. It works for me!


  3. January 20, 2015 at 12:37

    Reblogged this on Linux, Voip e Infra-estrutura da internet and commented:
    Achados e perdidos dos meus favoritos!


  4. Rolf
    January 2, 2015 at 9:51

    Still helpful in 2015, saved me more time and sweat. Thanks a lot!!


  5. amani
    March 14, 2014 at 8:24

    Thank you it works great for me but I would really like to know why did that happened knowing that I didn’t update mysql version.


    • March 14, 2014 at 9:19

      Thanks for your comment Amani. I don’t know why this happens to you. Maybe updating other ubuntu packages (like gnome-keyring?) mysql is affected.


    February 16, 2014 at 12:25

    NASEEM :
    am so thankful to you,it really help me.


    February 16, 2014 at 12:24

    am so thankful to you……. it really help me.


  8. Bhima
    January 31, 2014 at 15:17

    worked for me


  9. joel mwas
    September 11, 2013 at 7:51

    am so thankful to you……. it really help me.


  10. nathanmcbhqsgf
    September 4, 2013 at 23:38

    I am really pleased tto glance at this blog posts which contains tons of valuable data, thanks for providing
    such data.


  11. sabier
    August 16, 2013 at 13:15

    thank you sir


  12. Vivek
    August 1, 2013 at 22:17

    Thank You, the steps worked for mysql 5.1.69


    • August 2, 2013 at 7:00

      Thanks for your comment, Vivek


  13. July 25, 2013 at 1:27

    Hey! This is my first visit to your blog! We
    are a group of volunteers and starting a new project in a community in
    the same niche. Your blog provided us valuable information to work
    on. You have done a outstanding job!


  14. July 18, 2013 at 14:46

    This website was… how do I say it? Relevant!
    ! Finally I’ve found something that helped me. Thanks!


  15. Terra
    July 10, 2013 at 4:32

    This is actually a great blog, thanks a ton due to
    this. I had created to google and yahoo to get a number of many hours
    to seek out that placed.
    My partner and i hate anytime any time We yahoo and google intended for articles and reviews
    for you to experience I personally frequently come across useless article content and lots of spammy.

    You actually in plain english obtain care involving the complete spammy together with keep your site clear in
    addition to high-quality. Does one have means of my personal site?


  16. July 5, 2013 at 21:37

    Wonderful work! This is the kind of info that should be shared
    across the net. Disgrace on the search engines for now not positioning this post higher!

    Come on over and visit my site . Thanks =)


  17. can i use
    July 5, 2013 at 14:12

    It’s going to be end of mine day, except before end I am reading this wonderful paragraph to improve my experience.


  18. nigus
    January 17, 2013 at 12:37

    thanks . it works


  19. div
    January 16, 2013 at 12:30

    thanks a lot,, it worked


  20. Kdinesh
    October 10, 2012 at 6:58



  21. negrofeo
    September 12, 2012 at 20:03

    Excellent, thank you very much for the contribution several days looking for solutions but none served, thank you.


  22. ozi
    August 6, 2012 at 21:12

    when i close the first terminal it gives same error.If i dont close first terminal it works fine.What should i do sir ?


    • August 8, 2012 at 11:24

      Are you sure that you’ve killed the mysqld process and then restarted it?

      $ ps -ef | grep mysqld
      mysql 1233 1 0 07:41 ? 00:00:05 /usr/sbin/mysqld
      $ sudo kill -9 1233
      $ sudo service mysql start


  23. August 1, 2012 at 2:31

    Good, Working fine.


  24. Arunesh Shahi
    July 16, 2012 at 21:53

    Thank You miquel .
    but when i went for this it shows me a error inside of mysql like this —-
    echo “SET PASSWORD FOR snort@localhost=PASSWORD(‘***’);”|mysql -u root -p
    Enter password:
    ERROR 1290 (HY000) at line 1: The MySQL server is running with the –skip-grant-tables option so it cannot execute this statement..


    • July 17, 2012 at 7:07

      Hi Arunesh.
      If you are running in safe mode (–skip-grant-tables) you must enter the commands interactively.
      Try the same steps as me, open a mysql console and update the user as specified in the post.


  25. yumm
    July 7, 2012 at 15:13

    open another terminal to put mysql but give error
    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

    what to do? =.=


    • July 8, 2012 at 11:15

      Are you sure your MySQL server is up?
      Try this:
      ps -ef | grep mysql
      If you can’t see the mysqld process, then start it:
      sudo service mysqld start


  26. June 8, 2012 at 8:34

    You’re welcome, Tom


  27. Tom - New Hampshire, USA
    June 8, 2012 at 8:10

    Thank you Miguel. Your concise procedure worked for my 5.1.62… version of the server.


  1. November 7, 2015 at 12:55
  2. September 3, 2013 at 4:32
  3. November 24, 2012 at 14:15

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: