Menu

MySQL Error 1044: Access Denied to Database (42000)

Fix MySQL Error 1044 by checking the authenticated account and granting only the database or table privileges the operation needs.

Posted on By
On this page

MySQL Error 1044 (42000, ER_DBACCESS_DENIED_ERROR) means the server authenticated the connection, but the MySQL account used for the request lacks a privilege needed for the named database. A typical message is:

ERROR 1044 (42000): Access denied for user 'app_user'@'localhost' to database 'app_db'

The MySQL 8.4 error reference defines Error 1044. The missing privilege depends on the statement: reading a table needs SELECT, while creating a database needs CREATE. Do not grant broad server-wide permissions just to suppress the error.

Check which MySQL account is being used

Run these statements in the same connection that produced the error:

SELECT USER() AS connection_identity,
       CURRENT_USER() AS privilege_account;

SHOW GRANTS FOR CURRENT_USER();

CURRENT_USER() shows the MySQL account whose privileges are checked. It can differ from USER(), which reports the user and host supplied by the connection. MySQL documents this distinction in Information Functions.

SHOW GRANTS lists privileges assigned to the current account. If the application connects as 'app_user'@'%' but you grant access to 'app_user'@'localhost', you may have changed a different account. If the account uses roles, also check that the required role is active for the session.

Grant only the privilege the statement needs

Ask a database administrator, or use an account authorized to grant privileges. For example, if app_user needs to read one table, grant SELECT on that table to the exact account:

GRANT SELECT
ON `app_db`.`orders`
TO 'app_user'@'localhost';

If the application must read every table in app_db, use a database-level grant instead:

GRANT SELECT
ON `app_db`.*
TO 'app_user'@'localhost';

Replace the example database, table, user, and host with the real values. Grant only the operations the application needs, such as SELECT, INSERT, UPDATE, or DELETE. Database privileges apply to objects in that database; table privileges can be narrower. See the MySQL GRANT tutorial and privilege scope documentation.

The account issuing GRANT must itself be authorized to grant those privileges. If it cannot, ask the database administrator to apply the appropriate grant rather than changing the application to use a more powerful account.

Distinguish nearby errors

  • Error 1044 (42000): the account connected, but lacks access to the database or object.
  • Error 1045 (28000): the server rejected the account during connection authentication. See Error 1045 troubleshooting.
  • Error 1046 (3D000): a statement needs a default database, but none is selected.
  • Error 1049 (42000): the named database was not found on that server.

If the database name is wrong or the database is absent, see Error 1049: unknown database. For database selection, see Error 1046: no database selected. Browse more fixes in MySQL error troubleshooting.