- Rails 2.1 Sends Emails
- Rails 2.1 Uploads Files
- Rails 2.1 and AJAX
- Rails 2.1 Scaffolding
- Rails 2.1 Layouts
- Rails 2.1 Views
- Rails 2.1 Controllers
- Rails 2.1 Migrations
- Rails 2.1 Active Records
- Rails 2.1 Database Setup
- Rails 2.1 Examples
- Rails 2.1 Dir Structure
- Rails 2.1 Framework
- Rails 2.1 Installation
- Rails 2.1 Introduction
- Rails 2.1 Home
Advanced Ruby on Rails 2.1
- Rails 2.1 Tips & Tricks
- Rails 2.1 Unit Testing
- Rails 2.1 Routes System
- Rails 2.1 Error Handling
- Rails 2.1 Basic HTTP Auth
- Rails 2.1 RMagick Guide
Quick Reference Guide
Ruby on Rails 2.1 Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Ruby on Rails 2.1 - Database Setup
Before starting with this chapter, make sure your database server is setup and running. Ruby on Rails recommends to create three databases - a database each for development, testing, and production environment. According to convention, their names should be as follows −
pbrary_development
pbrary_production
pbrary_test
You should initiapze all three of them and create a username and password for them with full read and write privileges. We are using root user ID for our apppcation. In MySQL, a console session looks as follows −
mysql> create database pbrary_development; Query OK, 1 row affected (0.01 sec) mysql> use pbrary_development; Database changed mysql> grant all privileges on pbrary_development.* to root @ localhost identified by password ; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
You can do the same thing for the other two databases, pbrary_production and pbrary_test.
Configuring database.yml
At this point, you need to let Rails know about the username and password for the databases. You do this in the file database.yml, available in the C: ubypbraryconfig subdirectory of Rails Apppcation you created. This file has pve configuration sections for MySQL databases. In each of the sections you use, you need to change the username and password pnes to reflect the permissions on the databases you ve created.
When you finish, it should look something pke −
development: adapter: mysql encoding: utf8 database: pbrary_development username: root password: password host: localhost test: adapter: mysql encoding: utf8 database: pbrary_test username: root password: password host: localhost production: adapter: mysql encoding: utf8 database: pbrary_production username: root password: password host: localhost
NOTE − You can use similar setting for other databases if you are using any other database except MySQL.
What is Next?
The next two chapters explain how to model your database tables and how to manage those using Rails Migrations.
Advertisements