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
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 DATABASEwithout the globalCREATEprivilege.
How to fix it
-
See which account you are and what it may do.
SELECT CURRENT_USER(); SHOW GRANTS FOR CURRENT_USER();
-
As an administrator, grant the privileges the account needs on that database.
GRANT SELECT, INSERT, UPDATE, DELETE ON shop.* TO 'app'@'%';
-
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
1045Access denied for user1142Command denied to user for table1227Access denied; you need a privilege1049Unknown database916SQL Server: Login can't access the database42501PostgreSQL: permission denied
More access and privileges errors
1130Host is not allowed to connect1698Access denied for user (no password)1143Command denied to user for column1396Operation CREATE USER failed1419SUPER privilege needed with binary logging1449Definer user does not exist
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.
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.