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
About these ads
Categories: MySQL, ubuntu Tags: , , , ,
  1. amani
    March 14, 2014 at 8:24 | #1

    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 | #2

      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.

  2. NASEEM
    February 16, 2014 at 12:25 | #3

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

  3. NASEEM
    February 16, 2014 at 12:24 | #4

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

  4. Bhima
    January 31, 2014 at 15:17 | #5

    worked for me

  5. joel mwas
    September 11, 2013 at 7:51 | #6

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

  6. nathanmcbhqsgf
    September 4, 2013 at 23:38 | #7

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

  7. sabier
    August 16, 2013 at 13:15 | #8

    thank you sir

  8. Vivek
    August 1, 2013 at 22:17 | #9

    Thank You, the steps worked for mysql 5.1.69

  9. July 25, 2013 at 1:27 | #11

    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!

  10. July 18, 2013 at 14:46 | #12

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

  11. Terra
    July 10, 2013 at 4:32 | #13

    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?

  12. July 5, 2013 at 21:37 | #14

    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 =)

  13. can i use
    July 5, 2013 at 14:12 | #15

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

  14. nigus
    January 17, 2013 at 12:37 | #16

    thanks . it works

  15. div
    January 16, 2013 at 12:30 | #17

    thanks a lot,, it worked

  16. Kdinesh
    October 10, 2012 at 6:58 | #18

    thanks..

  17. negrofeo
    September 12, 2012 at 20:03 | #19

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

  18. ozi
    August 6, 2012 at 21:12 | #20

    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 | #21

      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

  19. August 1, 2012 at 2:31 | #22

    Good, Working fine.

  20. Arunesh Shahi
    July 16, 2012 at 21:53 | #23

    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 | #24

      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.

  21. yumm
    July 7, 2012 at 15:13 | #25

    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 | #26

      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

  22. June 8, 2012 at 8:34 | #27

    You’re welcome, Tom

  23. Tom – New Hampshire, USA
    June 8, 2012 at 8:10 | #28

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

  1. November 24, 2012 at 14:15 | #1
  2. September 3, 2013 at 4:32 | #2

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 29 other followers

%d bloggers like this: