Access denied for user to database
Error 1044 (SQLSTATE 42000) is returned when a user attempts to perform an operation on a database for which they have not been granted the required privilege. Unlike error 1045 which occurs at authentication, 1044 occurs after successful login when a specific database-level action is denied.
- 1The user account was created but no GRANT was issued for the target database
- 2The GRANT was issued on the wrong database name or with incorrect scope
- 3The user is connecting to a replica or a different server instance where grants have not been replicated
A user with no database-level privileges attempts to USE a database.
-- Run as a user without privileges on myapp_db USE myapp_db;
expected output
ERROR 1044 (42000): Access denied for user 'appuser'@'localhost' to database 'myapp_db'
Fix
Grant the required privileges
WHEN When the user legitimately needs access to the database.
-- Run as root or a privileged user GRANT SELECT, INSERT, UPDATE, DELETE ON myapp_db.* TO 'appuser'@'localhost'; FLUSH PRIVILEGES;
Why this works
GRANT issues the named privileges on the specified objects to the user. FLUSH PRIVILEGES reloads the in-memory privilege tables from the grant tables, though in modern MariaDB versions explicit GRANT statements take effect immediately without FLUSH.
✕ Grant GRANT ALL PRIVILEGES ON *.* to silence the error
This gives the user superuser-equivalent access to every database on the server, violating the principle of least privilege.
Password and account management changes mean some legacy grant syntax may behave differently. Use CREATE USER + GRANT in two steps.
MariaDB Server error code 1044 / ER_DBACCESS_DENIED_ERROR
MariaDB privilege system overview ↗Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev