পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Saturday, March 11, 2017

Ruby on Rails 2.1 - Database Setup

Before starting with this chapter, make sure your database server is setup and running well. Ruby on Rails recommends to create three databases. A database for each development, testing and production environment. According to convention their names should be −

  • library_development
  • library_production
  • library_test
You should initialize all three of them and create a user and password for them with full read and write privileges. I am using root user ID for my application. In MySQL, a console session in which you do this looks something like this −
mysql> create database library_development;
Query OK, 1 row affected (0.01 sec)
mysql> use library_development;
Database changed
mysql> grant all privileges on library_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)
Note − Here you would have to replace password with actual password you have set for your root userid.
If you are going to use testing and production databases then you should issue the same set of commands for each of the two databases library_production and library_test.

Configuring database.yml

At this point, you need to let Rails know about the user name and password for the databases. You do this in the file database.yml, available in the ~library\config subdirectory of Rails Application you created.
This file has live configuration sections for MySQL databases. In each of the sections you use, you need to change the username and password lines to reflect the permissions on the databases you've created.
In this example I'm using root as user ID and password as password.
When you finish, database.yml should look something like as follows −
development:
  adapter: mysql
  encoding: utf8
  database: library_development
  username: root
  password: password
  host: localhost
test:
  adapter: mysql
  encoding: utf8
  database: library_test
  username: root
  password: password
  host: localhost
production:
  adapter: mysql
  encoding: utf8
  database: library_production
  username: root
  password: password
  host: localhost
NOTE − You can use similar setting for other databases adapters in case you want to use any other database except MySQL.

What is next ?

Next two chapters will teach you how to model your database tables and how to manage them using Rails Migrations.

1 comment: