ARCHIVED: In MySQL, how do I resolve the error "Access denied for user: 'user_name@localhost'"?

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

When you log into your MySQL account via SSH with the command mysql -u user_name -p, you may see the following error message:

ERROR 1045: Access denied for user: 'user_name@localhost' (Using password: YES)

You will get this error when the user user_name does not have the right to access your MySQL database. To resolve the error, you must create a user with the following command:

  mysql> GRANT ALL ON *.* to user_name@localhost IDENTIFIED BY 'password';

Replace user_name with the user's username and password with the user's password.

Note: If you use ALL in the command above, you will give the user all privileges for the specified database. Instead, you can specify certain privileges (e.g., select, update, delete) in the command. Also, you can specify a particular database (e.g., FirstDB.*) rather than using *.*.

For more information, see MySQL User Privileges.

This is document awmx in the Knowledge Base.
Last modified on 2021-09-08 10:23:03.