← 返回命令列表

Linux command

rails-db 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Open a database console

rails db

Open a database console

rails db -e production

Open a database console

rails db --database=[database_name]

说明

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.

参数

-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

FAQ

What is the rails-db command used for?

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.

How do I run a basic rails-db example?

Run `rails db` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -e, --environment _ENV_ do in rails-db?

Specify the Rails environment (development, test, production)