MySQL: Error 1045 – Access denied for user

In this article, we are going to create a new MySQL user and discuss all related aspects of it. And in the process, we will solve MySQL Error 1045 (Access denied for user).

Error Details

Error Number1045
Error SymbolER_ACCESS_DENIED_ERROR
SQLSTATE28000
MessageAccess denied for user ‘%s’@’%s’ (using password: %s)
Possible Reason1. Access/Permission not granted for the user.
2. Remote access to the server is not allowed for that user.
3. Remote access to the server is not allowed at all (No remote access allowed).
Error TypeServer-Side Error

Let’s see how can we address all these possible reasons and solve the issue.

Using all the following queries, we are creating a user named myuser and password will be test1234.

Login to MySQL and execute the following query.

Create user

Create a new user that can be accessed from localhost:

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'test1234';

Grant permission

Give all permission to the user:

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost';

To give the user permission to only one database (say, DB name is testdb) use the following command:

GRANT ALL PRIVILEGES ON tested.* TO 'myuser'@'localhost';

Then you need to flush/reload the privilege:

FLUSH PRIVILEGES;

Allow Remote access

If you want to change the host and want it to be accessed from any computer:

UPDATE mysql.user SET Host=‘%’ WHERE Host='localhost' AND User='myuser';

Also, use the following command to reflect the permission changes immediately:

FLUSH PRIVILEGES;

Additionally, if you want it to access the MySQL server from a remote computer, then in the MySQL configuration file, comment the following line (if it is not already commented)

# bind 127.0.0.1

Related Errors

You may also face a few other MySQL errors due to the same reason. The same fix will work for these MySQL errors too.

Here is the list of errors related to MySQL Error: 1045:

Error NumberError SymbolSQLSTATEMessageError Type
1044ER_DBACCESS_DENIED_ERROR42000Access denied for user ‘%s’@’%s’ to database ‘%s’Server-Side Error
1698ER_ACCESS_DENIED_NO_PASSWORD_ERROR28000Access denied for user ‘%s’@’%s’Server-Side Error
MY-010925ER_ACCESS_DENIED_ERROR_WITHOUT_PASSWORDHY000Access denied for user ‘%s’@’%s’Server-Side Error
MY-010926ER_ACCESS_DENIED_ERROR_WITH_PASSWORDHY000Access denied for user ‘%s’@’%s’ (using password: %s)Server-Side Error

1 thought on “MySQL: Error 1045 – Access denied for user”

Leave a Comment


The reCAPTCHA verification period has expired. Please reload the page.