Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7813025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:42:47+00:00 2026-06-02T04:42:47+00:00

My database.yml looks like: adapter: mysql database: my_db username: user1 password: ‘123’ host: localhost

  • 0

My database.yml looks like:

adapter: mysql
database: my_db
username: user1
password: '123'
host: localhost

This is a non-rails application, just using rake/ruby for some scripting.

Can I set a default (dev) and production in this yaml file, or is that rails specific?

If yes, when running something like:

rake user:create

How do I pass in if it is production and therefore use the production db settings in the yaml file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:42:49+00:00Added an answer on June 2, 2026 at 4:42 am

    Where you read the yaml file into memory and parse it is a good place to put the logic to use the current environment (or a default if none is set). A simple way to do this is to rely on an environment variable (don’t use RAILS_ENV if it’s not a rails app, or RACK_ENV if it’s not a rack app).

    Use something like:

    my_env = ENV['MY_ENV_VARIABLE'] || 'development'
    db_settings = YAML::load(File.open(yml_file))[my_env]
    

    Then you can call rake via:

    MY_ENV_VARIABLE=production rake my_task
    

    Or if you want to add a param to the task itself, you can set it up to use

    rake my_task[production]
    

    (but that can get messy depending on if you have to quote the whole thing, like in zsh).

    Another approach that some libraries use (like heroku_san) is to have a separate task that sets the environment variable, and rely on calling multiple tasks, so you’d have a task :production that sets the environment variable and can then call

    rake production my_task
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my config/database.yml like this: development: adapter: postgresql database: psql_dev username: postgres min_messages:
I'm using mongoid 3.0 with rails 3.2.3. mongoid.yml looks like: development: sessions: default: database:
My database.yml looks something like this: # SQLite version 3.x # gem install sqlite3-ruby
I am using Doctrine with Symfony2. My config.yml file looks something like this:- Doctrine
I'm very new to Ruby and postgres. Below is my database.yml development: adapter: postgresql
How should my database.yml production look like when I am using Heroku and Amazon
I'm using Doctrine's 2 Tree-Nestedset extension with MySQL InndoDB database. The yml table schema
I have UTF-8 everywhere so why does Page.last.url.encoding return ASCII-8BIT? My database.yml: development: adapter:
I have the following developement section of my development.yml file: development: adapter: postgresql host:
In database.yml you define all the settings. How can I access those settings from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.