Ruby on Rails supports many different type of databases. How do you setup Ruby on Rails with your database? Here are some examples to help you out.


By default a Ruby on Rails project is generated to use SQLite for development. This database is great for development environments but not ideal for production.

Databases supported in Ruby on Rails:

  • MySQL
  • PostgreSQL
  • SQLite (default)
  • SQL Server
  • IBM DB2
  • Informix
  • Oracle
  • Firebird

MySQL

Your database.yml file will have the configuration:

development:
  adapter: mysql
  encoding: utf8
  database: test_development
  username: root
  password: password
  host: localhost

PostgreSQL

Install the native driver for PostgreSQL.

gem install postgres

Your database.yml file will have the configuration:

development:
  adapter: postgresql
  database: test_development
  username: root
  password: password
  host: localhost

SQLite

You will need to install the gem for SQLite support

gem install sqlite3-ruby

Your database.yml file will have the configuration:

development:
  adapter: mysql
  encoding: utf8
  database: test_development
  username: root
  password: password
  host: localhost

SQL Server

You will need to install the gem for SQLite support

gem install sqlite3-ruby

Your database.yml file will have the configuration:

development:
  adapter: sqlserver
  database: test_development
  username: root
  password: password
  host: localhost

Oracle

In Rails 2.0 support for Oracle is not set by default. You will need to download the oracle adapter.

svn co http://svn.rubyonrails.org/rails/adapters/oracle/lib/active_record/connection_adapters/

Copy the oracle_adapter.rb file to your Ruby connection adapters directory

[your ruby path]/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters

Your database.yml file will have the configuration:

# database.yml
development:
  adapter: oracle
  database: [your database as it appears on TNSNAMES.ora]
  username: [your username]
  password: [your password]