MySQL 8.4Lab-verified · 2026-11-30

MySQL ERROR 1049 (42000): Unknown database

No database with exactly that name exists on this server.

MySQL 8.4.13
1049 (42000): Unknown database 'shpo'

Jump to a cause

  1. 01Typo in the database name
  2. 02App connects to a database that does not exist on this server yet (new server, not restored)
  3. 03Different upper/lower case on Linux
  4. 04The database does not exist on this server yet

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

ERROR 1049 shows the database name MySQL looked for, in quotes. Compare it with SHOW DATABASES character by character, including case.

In most runs below, a database called shop existed. The error came from a typo, from an app account connecting to shop on a server where it had not been created yet, from Shop with a capital S, and from a shop_dev database that had not been created yet.

01Typo in the database name

USE shpo; failed with ERROR 1049: Unknown database 'shpo'. SHOW DATABASES listed shop, not shpo.

USE shop; worked and SELECT DATABASE() returned shop.

Setup
Setuprun as root
CREATE DATABASE shop;
OUTPUT
Query OK, 1 row affected (0.00 sec)
Reproducerun as root
USE shpo;
✕ ERROR
ERROR 1049 (42000): Unknown database 'shpo'
Checkrun as root
SHOW DATABASES;
OUTPUT
+--------------------+
| Database           |
+--------------------+
| information_schema |
| lab_a              |
| lab_b              |
| mysql              |
| performance_schema |
| shop               |
| sys                |
+--------------------+
7 rows in set (0.00 sec)
After the fixrun as root
USE shop;
SELECT DATABASE();
✓ SUCCESS
+------------+
| DATABASE() |
+------------+
| shop       |
+------------+
1 row in set (0.00 sec)

02App connects to a database that does not exist on this server yet (new server, not restored)

app_user had ALL ON shop.* and its connection settings named the database shop, but shop had not been created on this server (think of a new server where accounts were set up before the data was restored). The login itself failed with Unknown database 'shop'.

SHOW DATABASES had no shop, while SHOW GRANTS already showed the grant on shop.*. After CREATE DATABASE shop the same connection worked and SELECT DATABASE() returned shop.

Setup
Setuprun as root
CREATE USER 'app_user'@'%' IDENTIFIED BY 'App_Pw_2026';
GRANT ALL ON shop.* TO 'app_user'@'%';
OUTPUT
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
SELECT DATABASE();
✕ ERROR
ERROR 1049 (42000): Unknown database 'shop'
Checkrun as root
SHOW DATABASES;
SHOW GRANTS FOR 'app_user'@'%';
OUTPUT
+--------------------+
| Database           |
+--------------------+
| information_schema |
| lab_a              |
| lab_b              |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
6 rows 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)
Fixrun as root
CREATE DATABASE shop;
OUTPUT
Query OK, 1 row affected (0.01 sec)

If the account had no grant on that name at all, MySQL would answer ERROR 1044 (access denied) instead of 1049.

After the fixrun as app_user
$ mysql -h 127.0.0.1 -u app_user -p'App_Pw_2026' shop
SELECT DATABASE();
✓ SUCCESS
+------------+
| DATABASE() |
+------------+
| shop       |
+------------+
1 row in set (0.00 sec)

03Different upper/lower case on Linux

The database was created as shop, and USE Shop; failed with Unknown database 'Shop'. On this server @@lower_case_table_names was 0 and @@version_compile_os was Linux, so database names are case-sensitive.

USE shop; with the exact case worked.

Setup
Setuprun as root
CREATE DATABASE shop;
OUTPUT
Query OK, 1 row affected (0.00 sec)
Reproducerun as root
USE Shop;
✕ ERROR
ERROR 1049 (42000): Unknown database 'Shop'
Checkrun as root
SELECT @@lower_case_table_names, @@version_compile_os;
SHOW DATABASES LIKE 'shop';
OUTPUT
+--------------------------+----------------------+
| @@lower_case_table_names | @@version_compile_os |
+--------------------------+----------------------+
|                        0 | Linux                |
+--------------------------+----------------------+
1 row in set (0.00 sec)

+-----------------+
| Database (shop) |
+-----------------+
| shop            |
+-----------------+
1 row in set (0.00 sec)

Check @@lower_case_table_names first. When it is 0, write the name exactly as SHOW DATABASES shows it.

After the fixrun as root
USE shop;
SELECT DATABASE();
✓ SUCCESS
+------------+
| DATABASE() |
+------------+
| shop       |
+------------+
1 row in set (0.00 sec)

04The database does not exist on this server yet

CREATE TABLE shop_dev.orders (...) failed with Unknown database 'shop_dev'. Only shop existed; CREATE TABLE does not create the database for you.

After CREATE DATABASE IF NOT EXISTS shop_dev; the same CREATE TABLE succeeded.

Setup
Setuprun as root
CREATE DATABASE shop;
OUTPUT
Query OK, 1 row affected (0.01 sec)
Reproducerun as root
CREATE TABLE shop_dev.orders (id INT PRIMARY KEY, amount DECIMAL(10,2));
✕ ERROR
ERROR 1049 (42000): Unknown database 'shop_dev'
Fixrun as root
CREATE DATABASE IF NOT EXISTS shop_dev;
OUTPUT
Query OK, 1 row affected (0.00 sec)
After the fixrun as root
CREATE TABLE shop_dev.orders (id INT PRIMARY KEY, amount DECIMAL(10,2));
✓ SUCCESS
Query OK, 0 rows affected (0.01 sec)

FAQ

How do I fix Unknown database in MySQL?

Run SHOW DATABASES and use the name exactly as listed. If it is not in the list, create it with CREATE DATABASE first, as in the third case.

Is the MySQL database name case-sensitive?

On this Linux server with lower_case_table_names = 0, yes: USE Shop failed while USE shop worked.

Does CREATE TABLE db.table create the database automatically?

No. CREATE TABLE shop_dev.orders failed with ERROR 1049 until CREATE DATABASE shop_dev was run.

What is the difference between ERROR 1049 and ERROR 1046?

1049 means you named a database that does not exist. 1046 means you did not name any database at all.

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