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

August 25, 2008

The other day I got this error on one of our servers. Fantastico module in cpanel was showing the error: Unable to connect to mysql database.  While mysql service was running fine, the root user was unable to login to mysql database. I initially tried to reset the mysql root password like https://rhcelinuxguide.wordpress.com/2008/08/08/reset-mysql-root-password/   but that did not help.  The real issue was permission on the folder /var/lib/mysql/mysql .  It is supposed to be 711 , while it was  751.  That fixed it.


root@server1 [~]# mysql
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
root@server1 [~]#

root@server1 [/var/lib/mysql/mysql]# ls -lhd /var/lib/mysql
drwxr-x–x 179 mysql mysql 12K Aug 25 01:44 /var/lib/mysql/

root@server1 [/var/lib/mysql/mysql]# chmod  711 /var/lib/mysql/mysql

root@server1 [/var/lib/mysql/mysql]# ls -lhd /var/lib/mysql/mysql
drwx–x–x 2 mysql mysql 4.0K Aug 25 01:32 /var/lib/mysql/mysql/

root@server1 [/var/lib/mysql/mysql]# service mysql restart
Shutting down MySQL..

[  OK  ]
Starting MySQL                                             [  OK  ]
root@server1 [/var/lib/mysql/mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.51a-community MySQL Community Edition (GPL)Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer. 

mysql> quit
root@server1 [/var/lib/mysql/mysql]#

Worked for me !
If above steps does not work, you can try this:
root@server1 [~]# /etc/init.d/mysqld stop
root@server1 [~]# safe_mysqld –skip-grant-tables &
root@server1 [~]# mysql
root@server1 [~]# USE mysql
mysql>  UPDATE user SET password=password(“new root passwd”) WHERE user=”root”;
mysql> flush privileges;
mysql> exit 

root@server1 [~]# killall mysqld mysql

root@server1 [~]# /etc/init.d/mysqld start

You can check the root mysql password in /root/.my.cnf  ( assuming you have set it up)

Sample /root/.my.cnf

root@server1 [~]# cat /root/.my.cnf
root@server1 [~]#



  1. When i typed the following command :
    service mysql restart
    I got the errr msg service mysql not found

  2. # service mysqld restart

  3. when i tried typing service mysql restart, it produces error : unrecognized service.

  4. okay, i already tried the mysqld. and it works, but still producing the ” Access denied for user: ‘root@localhost'(Using password:No)

  5. BIG THANKS for that chmod 🙂 was desperate already

  6. Hello,
    In my case it’s not so much working…
    When I issue:
    & service mysql restart
    I get:
    mysql start/running, process 29880
    But when I require:
    & mysql
    I get the same previouse:
    ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

    More ideas?
    I’m under Ubuntu lucid…



    • i’m using ubuntu lucid too… & have same error… please…

  7. Another reason for the error could be permission issue, Click here for full details

  8. i have this error…

    Enter password: ****
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 19
    Server version: 5.1.48-community MySQL Community Server (GPL)

    Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    This software comes with ABSOLUTELY NO WARRANTY. This is free software,
    and you are welcome to modify and redistribute it under the GPL v2 license

    Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

    mysql> show grants;
    | Grants for root@localhost
    | GRANT UPDATE ON *.* TO ‘root’@’localhost’ IDENTIFIED BY PASSWORD ‘446a12100c85
    6ce9’ |
    1 row in set (0.00 sec)

    mysql> GRANT SELECT ON *.* TO ‘root’@’localhost’ IDENTIFIED BY PASSWORD ‘1234’;
    ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: Y

    …please help me……….

  9. why are you using different password for the same user one for granting update and the other for granting select? try using same passwd and check

  10. Howdy very nice web site!! Guy .. Excellent .. Superb .. I’ll bookmark your web site and take the feeds additionallyI am glad to search out so many helpful info here in the put up, we want develop more techniques in this regard, thanks for sharing. ekfggbbdcefcadbk

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: