MySQL 8.4Lab-verified · 2026-11-30

MySQL ERROR 1044 (42000): Access denied for user 'lab_b'@'%' to database 'shop'

The account is valid, but it has no privilege on that database (including the one named in the connection settings) for what it tried to do.

MySQL 8.4.13
1044 (42000): Access denied for user 'lab_b'@'%' to database 'shop'

Jump to a cause

  1. 01USE on a database the account has no grant for
  2. 02Wrong database name when connecting (JDBC URL, -D, DB_NAME)
  3. 03CREATE DATABASE without the global CREATE privilege
  4. 04LOCK TABLES with only SELECT (mysqldump error)

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-30 · container image mysql:8.4

ERROR 1044 is a database-level access error. The user and password were accepted (a bad password would be ERROR 1045); the account just has no grant on the named database, whether that name comes from the connection settings or from the statement it ran.

The four runs below are the usual cases. Start with SHOW GRANTS FOR 'user'@'host'; as an admin to see what the account actually has.

01USE on a database the account has no grant for

lab_b only had privileges on its own database. USE shop failed with ERROR 1044 (42000): Access denied for user 'lab_b'@'%' to database 'shop'.

SHOW GRANTS showed only USAGE ON *.* and ALL ON lab_b.*. After root ran GRANT SELECT ON shop.* TO lab_b, USE shop worked and SELECT * FROM orders returned the row.

Setup
Setuprun as root
CREATE DATABASE shop;
CREATE TABLE shop.orders (id INT PRIMARY KEY, amount DECIMAL(10,2));
INSERT INTO shop.orders VALUES (1, 100.00);
OUTPUT
Query OK, 1 row affected (0.00 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 1 row affected (0.01 sec)
Reproducerun as lab_b
USE shop;
✕ ERROR
ERROR 1044 (42000): Access denied for user 'lab_b'@'%' to database 'shop'
Checkrun as root
SHOW GRANTS FOR lab_b;
OUTPUT
+--------------------------------------------------+
| Grants for lab_b@%                               |
+--------------------------------------------------+
| GRANT USAGE ON *.* TO `lab_b`@`%`                |
| GRANT ALL PRIVILEGES ON `lab_b`.* TO `lab_b`@`%` |
+--------------------------------------------------+
2 rows in set (0.00 sec)
Fixrun as root
GRANT SELECT ON shop.* TO lab_b;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
After the fixrun as lab_b
USE shop;
SELECT * FROM orders;
✓ SUCCESS
+----+--------+
| id | amount |
+----+--------+
|  1 | 100.00 |
+----+--------+
1 row in set (0.00 sec)

02Wrong database name when connecting (JDBC URL, -D, DB_NAME)

app_user had ALL ON shop.*, but the connection asked for database shop_db. The login was refused with Access denied for user 'app_user'@'%' to database 'shop_db', which is what an app sees when the database name in its connection settings is wrong.

Note that shop_db does not exist, yet the error is 1044, not 1049 (Unknown database): for an account without rights on that name, MySQL reports access denied. SHOW DATABASES LIKE 'shop%' showed only shop, and SHOW GRANTS showed the grant on shop.*. Connecting with database shop worked and the SELECT returned the row.

Setup
Setuprun as root
CREATE DATABASE shop;
CREATE TABLE shop.orders (id INT PRIMARY KEY, amount DECIMAL(10,2));
INSERT INTO shop.orders VALUES (1, 100.00);
CREATE USER 'app_user'@'%' IDENTIFIED BY 'App_Pw_2026';
GRANT ALL ON shop.* TO 'app_user'@'%';
OUTPUT
Query OK, 1 row affected (0.00 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)
Reproducerun as app_user
$ mysql -h 127.0.0.1 -u app_user -p'App_Pw_2026' shop_db
SELECT * FROM orders;
✕ ERROR
ERROR 1044 (42000): Access denied for user 'app_user'@'%' to database 'shop_db'
Checkrun as root
SHOW DATABASES LIKE 'shop%';
SHOW GRANTS FOR 'app_user'@'%';
OUTPUT
+------------------+
| Database (shop%) |
+------------------+
| shop             |
+------------------+
1 row in set (0.00 sec)

+----------------------------------------------------+
| Grants for app_user@%                              |
+----------------------------------------------------+
| GRANT USAGE ON *.* TO `app_user`@`%`               |
| GRANT ALL PRIVILEGES ON `shop`.* TO `app_user`@`%` |
+----------------------------------------------------+
2 rows in set (0.00 sec)
After the fixrun as app_user
$ mysql -h 127.0.0.1 -u app_user -p'App_Pw_2026' shop
SELECT * FROM orders;
✓ SUCCESS
+----+--------+
| id | amount |
+----+--------+
|  1 | 100.00 |
+----+--------+
1 row in set (0.00 sec)

03CREATE DATABASE without the global CREATE privilege

CREATE DATABASE report as lab_b failed with ERROR 1044 for database 'report'. Creating a new database needs CREATE on that database name, which lab_b did not have.

root created the database and ran GRANT ALL ON report.* TO lab_b. Then lab_b could create report.daily, and SHOW TABLES FROM report listed it.

Reproducerun as lab_b
CREATE DATABASE report;
✕ ERROR
ERROR 1044 (42000): Access denied for user 'lab_b'@'%' to database 'report'
Fixrun as root
CREATE DATABASE report;
GRANT ALL ON report.* TO lab_b;
OUTPUT
Query OK, 1 row affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)
After the fixrun as lab_b
CREATE TABLE report.daily (d DATE PRIMARY KEY, total INT);
SHOW TABLES FROM report;
✓ SUCCESS
Query OK, 0 rows affected (0.01 sec)

+------------------+
| Tables_in_report |
+------------------+
| daily            |
+------------------+
1 row in set (0.00 sec)

04LOCK TABLES with only SELECT (mysqldump error)

lab_b had SELECT on shop.*, but LOCK TABLES shop.orders READ failed with ERROR 1044. This is the same check that makes mysqldump stop with when using LOCK TABLES, because mysqldump locks tables by default.

SHOW GRANTS showed SELECT ON shop.* only. After GRANT LOCK TABLES ON shop.* TO lab_b, LOCK TABLES and UNLOCK TABLES both returned Query OK.

Setup
Setuprun as root
CREATE DATABASE shop;
CREATE TABLE shop.orders (id INT PRIMARY KEY, amount DECIMAL(10,2));
GRANT SELECT ON shop.* TO lab_b;
OUTPUT
Query OK, 1 row affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)
Reproducerun as lab_b
LOCK TABLES shop.orders READ;
✕ ERROR
ERROR 1044 (42000): Access denied for user 'lab_b'@'%' to database 'shop'
Checkrun as root
SHOW GRANTS FOR lab_b;
OUTPUT
+--------------------------------------------------+
| Grants for lab_b@%                               |
+--------------------------------------------------+
| GRANT USAGE ON *.* TO `lab_b`@`%`                |
| GRANT SELECT ON `shop`.* TO `lab_b`@`%`          |
| GRANT ALL PRIVILEGES ON `lab_b`.* TO `lab_b`@`%` |
+--------------------------------------------------+
3 rows in set (0.00 sec)
Fixrun as root
GRANT LOCK TABLES ON shop.* TO lab_b;
OUTPUT
Query OK, 0 rows affected (0.00 sec)
After the fixrun as lab_b
LOCK TABLES shop.orders READ;
UNLOCK TABLES;
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

FAQ

What is the difference between ERROR 1044 and ERROR 1045?

1045 means the user, host and password did not match any account. 1044 means they matched, but the account has no privilege on that database, either the one in the connection settings or the one in the statement.

I get 1044 for a database that doesn't exist. Why not 1049 Unknown database?

For an account with no rights on that name, MySQL answers with access denied (1044). In our run connecting to the nonexistent shop_db gave 1044. Check the database name in your connection settings.

How do I see which databases a MySQL user can access?

As an admin run SHOW GRANTS FOR 'user'@'host';. In the runs above it showed lines like GRANT SELECT ON shop.* TO lab_b.

mysqldump fails with 1044 when using LOCK TABLES. How do I fix it?

Give the dump user LOCK TABLES on the database: GRANT LOCK TABLES ON shop.* TO 'user'@'host';. In our run that made LOCK TABLES work.

Do I need FLUSH PRIVILEGES after GRANT?

Not for GRANT. In the runs above the new grant worked right away in the next session without FLUSH PRIVILEGES.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13