RORGURU.COM
 

Database Connection

 

Before starting any Rails application, we have to setup the connection with database. When we will create any Rails project, it will generate a .yml file called database.yml in config folder of a Rails app. The path of this yml file will be config/database.yml. Here three types of database conventions we will get :

development:    
adapter:   mysql/oracle/SQLite/SQlServer
/DB2/PostgreSQL
database:   project_name_development
username:   root
password:   [password]
host:   localhost
production:    
adapter:   mysql/oracle/SQLite/SQlServer
/DB2/PostgreSQL
database:   project_name_production
username:   root
password:   [password]
host:   localhost
test:    
adapter:   mysql/oracle/SQLite/SQlServer
/DB2/PostgreSQL
database:   project_name_test
username:   root
password:   [password]
host:   localhost

To create database, we have to run rake db:create in console of the rails project. By this command, we can create database. By default it will create database in development mode. After creating the database, we can run the Rails application.

Adapter : This specifies the connection information for mysql database and the information value will be mysql.


Database: Here we write our desired database name.


Password: This is also a parameter which contain the password for user we want to connect the database.
Host: This is also an optional parameter which contains the domain for the machine of the database.