MySQL: ERROR 1049 (42000): Unknown database

Diagnose and fix MySQL 'Unknown database' errors caused by typos or case sensitivity on Linux filesystems.

MySQL produces "ERROR 1049 (42000): Unknown database 'dbname'" when the specified database does not exist on the server.

What Causes "ERROR 1049" in MySQL

The database name is misspelled. MySQL database names are case-sensitive on Linux (because the filesystem is case-sensitive). A database created as MyApp cannot be accessed as myapp.

The database was never created, or it was dropped.

How to Fix

  1. List all databases to find the correct name:
SHOW DATABASES;
  1. Create the database if it does not exist:
CREATE DATABASE myapp;
  1. Use the exact case when connecting:
mysql -u root -p MyApp