Tenglun Tan
Tenglun Tan

Reputation: 21

Mysql error: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

This is driving me crazy...when I try to login to Mysql.

user-MacBook:~ user$ cd /usr/local/mysql/bin
user-MacBook:bin user$ ./mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
user-MacBook:bin user$ ./mysql
ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: NO)

Someone would help? Thankyou!!

Upvotes: 2

Views: 4238

Answers (1)

Jong Han Kim
Jong Han Kim

Reputation: 41

I think, You have input wrong password... In my case, representing like this if i have put wrong passwd.

jonghan@jonghan-MS-7817:~$ /usr/bin/mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

In second case is same issue.

If you have forgotten your password, i recommend to reset your mysql root password.

First of all, you have to stop mysql service.

#sudo service mysql stop

Second, Add 'skip-grant-tables' in your my.conf or my.cnf file.

In my case (MySQL v5.7.17), mysqld.cnf is in the '/etc/mysql/mysql.conf.d'.

Almost my.conf / my.cnf file shows like this.

[mysqld]
user         = mysql
pid-file     = /var/run/mysqld/mysqld.pid
socket       = /var/run/mysqld/mysqld.sock
port         = 3306
basedir      = /usr
datadir      = /var/lib/mysql
tmpdir       = /tmp
lc-messages-dir = /usr/share/mysql

skip-external-locking

skip-grant-tables         /*** You Add this code! ***/

Next, restart mysql service.

#sudo service mysql start

And, open your mysql service. In your case,

$ cd /usr/local/mysql/bin
$ ./mysql -u root

Then, You can login without authenticate.

Next, You should change password for 'root'.

mysql> UPDATE user SET password=PASSWORD('yourpassword') WHERE user='root';

After All, restore my.conf / my.cnf / mysqld.cnf and so on. (Delete 'skip-grant-tables')

Finally, restart mysql service.

$ sudo service mysql restart

If you cannot access mysql though following these steps, i recommend to Re-setup Mysql.

Thanks!

Upvotes: 1

Related Questions