Before starting with this chapter, make sure your database server is setup and running. 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> 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) |
You can do same thing for two more databases library_production andlibrary_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 theC:\ruby\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.
When you finish, it should look something like:
development: adapter: mysql database: library_development username: root password: [password] host: localhost test: adapter: mysql database: library_test username: root password: [password] host: localhost production: adapter: mysql database: library_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.
No comments:
Post a Comment