ERROR 1046 (3D000)

Unknown Database Error in CREATE TABLE – Real Fix

You get this when MySQL can't find the database you said to put the table in. Usually a typo or you forgot to create it first.

When This Error Pops Up

You're sitting there writing a simple CREATE TABLE statement in MySQL, something like:

CREATE TABLE mydb.users (id INT);

And MySQL throws back:

ERROR 1046 (3D000): Unknown database 'mydb'

This happens when you've got the database name spelled wrong, or you never created that database in the first place. I've seen this a hundred times with new devs who copy-paste code from a tutorial and the database name doesn't match what's on their server.

Root Cause – Plain English

MySQL is strict. When you say mydb.users, it looks for a database called mydb. If that database doesn't exist, MySQL doesn't guess – it stops with error 1046. You either:

  • Typed the database name wrong (common with uppercase vs lowercase on Linux – MySQL is case-sensitive there)
  • Haven't created the database yet (forgot to run CREATE DATABASE first)
  • Are in the wrong server (you're on a different MySQL instance that doesn't have that database)

The fix is simple: check the database exists, then use it correctly.

The Fix – Step by Step

  1. Connect to MySQL
    Open your MySQL client (command line, Workbench, or whatever you use). Type your password when asked.
    Expected: You'll see the mysql> prompt.

  2. List all databases
    Run:
    SHOW DATABASES;

    Expected: A list of database names. Look for the one you tried to use, like mydb. If it's not there, that's your problem.

  3. If the database is missing, create it
    Type:
    CREATE DATABASE mydb;

    (Replace mydb with the exact name you want.)
    Expected: Query OK, 1 row affected.

  4. Now tell MySQL to use that database
    Run:
    USE mydb;

    Expected: Database changed. Now MySQL knows you're working inside mydb.

  5. Create your table without the database prefix
    Now you can just write:
    CREATE TABLE users (id INT);

    Or if you really want to include the database name, it'll work now because the database exists:
    CREATE TABLE mydb.users (id INT);

    Expected: Query OK, 0 rows affected.

If It Still Fails – Check These

  • Check for typos – Did you write mydb or my-db? Hyphens in database names are trouble unless you escape them with backticks. Avoid hyphens.
  • Case sensitivity on Linux – MySQL on Linux treats MyDB and mydb as different. On Windows they're the same. If your server is Linux, use lowercase consistently.
  • You're connected to the right server – Run SELECT @@hostname; to see which machine you're on. Maybe you're on a staging server that doesn't have that database.
  • Did someone drop the database? – Run SHOW DATABASES again. If the database was there a minute ago but now it's gone, someone deleted it.
  • Privileges issue – Run SHOW GRANTS; to see what you're allowed to do. If you can't see any databases except information_schema, you probably don't have permission to see or create the one you need. Talk to your DBA.

That's it. Error 1046 is almost always a missing database or a spelling mistake. Create the database, use it, and the table creation will work.

Related Errors in Database Errors
null Cassandra gossip protocol failure when node restarts Msg 217, Level 16, State 1 Stored Procedure SQL Stack Overflow – Quick Fixes That Work ORA-01555 Fix ORA-01555 snapshot too old: real causes and cures 0X000020FB Fix AD Replication Error 0x000020FB: Inconsistent DIT Database

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.