// MySQL error reference

MySQL error 1044: Access denied for user to database

The login worked, but the account has no privileges on the database it tried to use. Grant privileges on that database or connect to one the account can use.

Error number
1044
Name
ER_DBACCESS_DENIED_ERROR
SQLSTATE
42000
Category
Access and privileges
Error message
Access denied for user '%s'@'%s' to database '%s'

What it means

Unlike 1045, the password check passed: MySQL knows who you are. 1044 means the account has no privilege at all on the named database, so it can't select it with USE, name it in the connection, or create it.

Privileges are granted per account ('user'@'host'), so the same user name connecting from another host can have different rights.

Common causes

  • The account was created but never granted anything on the database.
  • Privileges were granted to a different host part, for example 'app'@'localhost' while you connect as 'app'@'%'.
  • The connection string names the wrong database, or a database the account was never meant to use.
  • Trying to CREATE DATABASE without the global CREATE privilege.

How to fix it

  1. See which account you are and what it may do.

    SELECT CURRENT_USER();
    SHOW GRANTS FOR CURRENT_USER();
  2. As an administrator, grant the privileges the account needs on that database.

    GRANT SELECT, INSERT, UPDATE, DELETE ON shop.* TO 'app'@'%';
  3. If the grant went to another host part, check the accounts that exist for the user name.

    SELECT user, host FROM mysql.user WHERE user = 'app';

Related errors

More access and privileges errors

The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.

// fewer errors, faster fixes

Work on MySQL in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.