Error
Error Code: 1049

MariaDB Error 1049: Unknown Database Specified

📦 MariaDB
📋

Description

MariaDB Error 1049, 'Unknown database', indicates that the MariaDB server could not locate or identify the database name provided in a connection attempt or SQL query. This error typically occurs when the specified database does not exist, is misspelled, or the connecting user lacks the necessary permissions to access it.
💬

Error Message

Unknown database '%s'
🔍

Known Causes

4 known causes
⚠️
Database Does Not Exist
The database name provided in the connection string or SQL query has not been created on the MariaDB server.
⚠️
Incorrect Database Name
A typo, incorrect casing, or an invalid database name was entered in the client application, script, or SQL statement.
⚠️
Misconfigured Application
The application or client is configured to connect to a database that is either not present or incorrectly referenced on the MariaDB server.
⚠️
Insufficient User Privileges
The connected user account lacks the necessary permissions to access or even view the specified database, making it appear 'unknown'.
🛠️

Solutions

4 solutions available

1. Create the Missing Database easy

Create the database if it should exist

1
Connect to MariaDB as root
mysql -u root -p
2
Create the database
CREATE DATABASE my_database
    CHARACTER SET utf8mb4
    COLLATE utf8mb4_unicode_ci;
3
Grant privileges to user
GRANT ALL PRIVILEGES ON my_database.* TO 'username'@'localhost';
FLUSH PRIVILEGES;

2. Verify Database Name easy

Check spelling and available databases

1
List all existing databases
SHOW DATABASES;
2
Search for similar database names
SHOW DATABASES LIKE '%mydb%';
3
Check connection string in your application
# Common locations:
# PHP: config.php, .env, database.php
# Node.js: .env, config.js
# Python: settings.py, .env
# Java: application.properties

3. Fix Application Configuration easy

Update database name in your app config

1
Laravel (.env)
DB_DATABASE=correct_database_name
2
Node.js connection
const connection = mysql.createConnection({
    host: 'localhost',
    user: 'username',
    password: 'password',
    database: 'correct_database_name'  // Fix this
});
3
Python (Django settings.py)
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'correct_database_name',  # Fix this
        ...
    }
}

4. Check User Permissions medium

User might not have access to see the database

1
Check what databases user can see
-- As the user
SHOW DATABASES;
2
As root, check user privileges
SHOW GRANTS FOR 'username'@'localhost';
3
Grant access to the database
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
🔗

Related Errors

5 related errors