Skip to content

Database Does Not Exist

Error message

                database does not exist
              

Quick summary

You tried to connect to a database that does not exist on the server — the name may be misspelled or the database not yet created.

Why this happens

  • Typo in the database name in the connection string

  • The database has not been created yet

  • Connecting to the wrong server that does not have the database

  • The database was dropped

Minimal example

✗ Broken code
psql -h localhost -U postgres -d myapp_db
# → database "myapp_db" does not exist
✓ Fixed code
# Create the database first
psql -h localhost -U postgres -c "CREATE DATABASE myapp_db"
# Then connect
psql -h localhost -U postgres -d myapp_db

The database did not exist. Creating it first allows the connection to succeed.

How to diagnose

  • Check the database name in your connection string

  • List all databases: \l in psql or SHOW DATABASES in MySQL

  • Verify you are connecting to the correct server

How to fix

  • Fix the database name in the connection string

  • Create the database: CREATE DATABASE dbname

  • Connect to the correct server that has the database

How to prevent

  • Use environment variables for database names to avoid typos

  • Create databases as part of your deployment/setup script

  • Document database names and their environments

Related Resources

Related Glossary

Related Lessons

← Back to language