1049ERRORTier 1 — Safe✅ HIGH confidenceUnknown database
What this means
Error 1049 (SQLSTATE 42000) is returned when a USE statement or a connection string specifies a database that does not exist on the server. It is one of the most common connection-time errors in application deployment.
Why it happens
- 1The database was not created before the application started
- 2The database name in the connection string has a typo
- 3The database was created on a different server or environment
- 4The database was accidentally dropped
How to reproduce
A USE statement references a database that does not exist.
USE myapp_production;Fix 1: Create the database
When the database should exist but was never created.
CREATE DATABASE IF NOT EXISTS myapp_production
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;Why this works
CREATE DATABASE creates the schema directory and registers the database in information_schema. IF NOT EXISTS prevents an error if it was already created by another process.
Fix 2: List existing databases to find the correct name
When the database exists but the name may be wrong.
SHOW DATABASES;Why this works
SHOW DATABASES lists all databases the current user has access to, allowing the correct name to be confirmed.
What not to do
Create an empty database in production without running migrations
Why it's wrong: An empty database will cause further errors when the application attempts to query non-existent tables. Always run schema migrations after creating the database.
Version notes
All versionsMariaDB database names are case-sensitive on case-sensitive filesystems (Linux) and case-insensitive on case-insensitive filesystems (Windows, macOS).Sources
📚 Official docs: https://mariadb.com/kb/en/create-database/
🔧 Source ref: MariaDB Server error code 1049 / ER_BAD_DB_ERROR
📖 Further reading: MariaDB CREATE DATABASE
Confidence assessment
✅ HIGH confidence
Stable.
See also
🔗 Related errors
📄 Reference pages