MySQL - ERROR 1045 - Access denied MySQL - ERROR 1045 - Access denied linux linux

MySQL - ERROR 1045 - Access denied


If you actually have set a root password and you've just lost/forgotten it:

  1. Stop MySQL
  2. Restart it manually with the skip-grant-tables option: mysqld_safe --skip-grant-tables

  3. Now, open a new terminal window and run the MySQL client: mysql -u root

  4. Reset the root password manually with this MySQL command: UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';If you are using MySQL 5.7 (check using mysql --version in the Terminal) then the command is:

    UPDATE mysql.user SET authentication_string=PASSWORD('password')  WHERE  User='root';
  5. Flush the privileges with this MySQL command: FLUSH PRIVILEGES;

From http://www.tech-faq.com/reset-mysql-password.shtml

(Maybe this isn't what you need, Abs, but I figure it could be useful for people stumbling across this question in the future)


Try connecting without any password:

mysql -u root

I believe the initial default is no password for the root account (which should obviously be changed as soon as possible).


use this command to check the possible output

mysql> select user,host,password from mysql.user;

output

mysql> select user,host,password from mysql.user;+-------+-----------------------+-------------------------------------------+| user  | host                  | password                                  |+-------+-----------------------+-------------------------------------------+| root  | localhost             | *8232A1298A49F710DBEE0B330C42EEC825D4190A || root  | localhost.localdomain | *8232A1298A49F710DBEE0B330C42EEC825D4190A || root  | 127.0.0.1             | *8232A1298A49F710DBEE0B330C42EEC825D4190A || admin | localhost             | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 || admin | %                     |                                           |+-------+-----------------------+-------------------------------------------+5 rows in set (0.00 sec)
  1. In this user admin will not be allowed to login from another host though you have granted permission. the reason is that user admin is not identified by any password.
  2. Grant the user admin with password using GRANT command once again

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED by 'password'

then check the GRANT LIST the out put will be like his

mysql> select user,host,password from mysql.user;+-------+-----------------------+-------------------------------------------+| user  | host                  | password                                  |+-------+-----------------------+-------------------------------------------+| root  | localhost             | *8232A1298A49F710DBEE0B330C42EEC825D4190A || root  | localhost.localdomain | *8232A1298A49F710DBEE0B330C42EEC825D4190A || root  | 127.0.0.1             | *8232A1298A49F710DBEE0B330C42EEC825D4190A || admin | localhost             | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 || admin | %                     | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |+-------+-----------------------+-------------------------------------------+5 rows in set (0.00 sec)

if the desired user for example user 'admin' is need to be allowed login then use once GRANT command and execute the command.

Now the user should be allowed to login.