LinuxCommandLibrary

rails-db

Open database console for Rails application

TLDR

Open a database console for the current environment

$ rails db
copy
Open a database console for production
$ rails db -e production
copy
Open a database console with a specific database configuration
$ rails db --database=[database_name]
copy

SYNOPSIS

rails db [-e environment] [--database name] [-h]

DESCRIPTION

rails db (also known as rails dbconsole) opens an interactive session with the database configured for your Rails application. It automatically detects the database adapter and launches the appropriate client (psql for PostgreSQL, mysql for MySQL, sqlite3 for SQLite, etc.).
The command reads database configuration from config/database.yml and connects using the credentials and connection details specified there. This provides quick access to the database without manually remembering connection strings.

PARAMETERS

-e, --environment ENV

Specify the Rails environment (development, test, production)
--database name
Connect to a specific database when multiple databases are configured
-h, --help
Show help information

CAVEATS

Requires the corresponding database client to be installed on the system (psql, mysql, sqlite3, etc.). The command will fail if the client is not in the PATH.
Database credentials are read from the configuration file. Ensure sensitive credentials are properly secured, especially in production environments.

SEE ALSO

rails(1), rails-console(1), psql(1), mysql(1), sqlite3(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community