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
psql -h localhost -U postgres -d myapp_db
# → database "myapp_db" does not exist# Create the database first
psql -h localhost -U postgres -c "CREATE DATABASE myapp_db"
# Then connect
psql -h localhost -U postgres -d myapp_dbThe 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:
\lin psql orSHOW DATABASESin MySQLVerify you are connecting to the correct server
How to fix
Fix the database name in the connection string
Create the database:
CREATE DATABASE dbnameConnect 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 Lessons
- Database Overview
Learn about database setup.