ERROR 1049 (42000): Unknown database
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 -pSHOW 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.1Ensure 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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro