March 01, 2015

Home » » » Database Setup On Rails - Use MySQL Database On Rails

Database Setup On Rails - Use MySQL Database On Rails

Posted by Unknown
0

Install MySQL server

$ sudo apt-get install mysql-server

Install MySQL2 gem

$ sudo apt-get install libmysqlclient-dev

Create a new web application

# rails new sample_app 
or
# rails new sample_app -d mysql

Configure database.yml

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: username
  password: password
  socket: /var/run/mysqld/mysqld.sock

development:
  <<: *default
  database: sample_app_development
test:
  <<: *default
  database: sample_app_test
production:
  <<: *default
  database: sample_app_production
 
Then run command to create database
# rake db:create
Or
# mysql -u root -p
mysql> create database sample_app_development;
Query OK, 1 row affected (0.01 sec)

mysql> grant all privileges on sample_app_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)
sample_app_test and sample_app_production databases also create as above. May you need:
# rake db:migrate

Running web application

# rails s

Open browser and type http://:3000 or http://localhost:3000






0 comments:

Post a Comment

Popular Posts

Labels

Archive

 

Blogroll

Recepies

Flickr Images

Copyright © 2014. Tutorials Blog - All Rights Reserved