DATABASE_URL
What is DATABASE_URL?
The DATABASE_URL
is a standardized environment variable way to specify database connection details and is commonly used in various deployment environments and hosting platforms.
DATABASE_URL
contains a URL string with information needed to connect to a database. This URL includes details like the database type (e.g., PostgreSQL, MySQL), the host, port, database name, and authentication credentials.
There are three types supported by the application:
- SQLite3: this is ephemeral and lost on container restart
- PostgreSQL: The Postgres Database - persistent
- Mysql (or MariaDB): Persistent
Remember to replace the placeholders in these examples (e.g., username
, password
, hostname
, port
, database_name
) with the actual credentials and database information for your specific setup.
SQLite3
Note: SQLite3 is the default database type. If DATABASE_URL is not specified, it will default to this ephemeral backend storage.
For SQLite3, the DATABASE_URL
typically looks like this:
sqlite3:db/db.sqlite3
sqlite3://
is the protocol.db/db.sqlite3
is the path to your SQLite database file.
Example
sqlite3:///app/db/development.sqlite3
PostgreSQL
For PostgreSQL, the DATABASE_URL
follows this format:
postgres://username:password@hostname:port/database_name
postgres://
is the protocol.username:password
are your PostgreSQL credentials.hostname
is the host where your PostgreSQL database is running.port
is the port number for the database (typically 5432).database_name
is the name of your PostgreSQL database.
Warning: hostname
values with underscores are not supported. See #1602
Example
postgres://myuser:mypassword@localhost:5432/mydatabase
MySQL
For MySQL, the DATABASE_URL
format is similar to PostgreSQL:
mysql2://username:password@hostname:port/database_name
mysql2://
is the protocol.username:password
are your MySQL credentials.hostname
is the MySQL server host.port
is the MySQL server port (typically 3306).database_name
is the name of your MySQL database.
Warning: hostname
values with underscores are not supported. See #1602
Example
mysql2://myuser:mypassword@localhost:3306/mydatabase
MariaDB
MariaDB is compatible with MySQL, so the DATABASE_URL
format for MariaDB is the same as for MySQL:
mysql2://username:password@hostname:port/database_name
mysql2://
is the protocol.username:password
are your MariaDB credentials.hostname
is the MariaDB server host.port
is the MariaDB server port (typically 3306).database_name
is the name of your MariaDB database.
Warning: hostname
values with underscores are not supported. See #1602
Example
mysql2://myuser:mypassword@localhost:3306/mydatabase