Skip to content
ERROR 1049 (42000): Unknown database

ERROR 1049 (42000): Unknown database

DodaTech 2 min read

MySQL ERROR 1049 (42000) appears when the database specified in your query or connection string does not exist on the server. The solution is to verify the database name and create it if necessary.

What It Means

The MySQL server could not find a database matching the name you provided. The error message includes the database name that was not found, such as Unknown database 'mydb'.

Why It Happens

  • Typo in the database name in your application’s connection string.
  • The database was never created or was accidentally dropped.
  • You are connected to the wrong MySQL server instance.
  • Case sensitivity mismatch on case-sensitive file systems (Linux).

How to Fix It

1. List all available databases

Connect to MySQL and view existing databases:

mysql -u root -p
SHOW DATABASES;

Compare the output with the name used in your application.

2. Create the missing database

If the database does not exist, create it:

CREATE DATABASE mydb;
CREATE DATABASE IF NOT EXISTS mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

3. Verify the connection string

Check your application configuration (.env, config/database.php, application.properties, etc.):

# Laravel .env example
DB_DATABASE=mydb
DB_USERNAME=root
DB_HOST=127.0.0.1

Ensure the DB_DATABASE value exactly matches the database name from SHOW DATABASES.

4. Select the database explicitly

Before running queries, confirm the database is selected:

USE mydb;
SELECT DATABASE();

FAQ

Does MySQL database name case matter?
On Linux, database names are case-sensitive because they map to filesystem directories. On Windows and macOS, they are case-insensitive by default. Set lower_case_table_names=1 in my.cnf for consistent behavior.
What if the database shows in SHOW DATABASES but my app still gets 1049?
Your app may be connecting to a different MySQL server or port. Check DB_HOST and DB_PORT in your config. Run SELECT @@hostname, @@port; to confirm which server you are on.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro