Menu

Tuesday, November 16, 2010

How to import .sql into DB in RoR

In database.yml:


development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: DBName_development

  pool: 5
  username: root
  password: Your Password (If you have)
  host: localhost


test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: DBName_test
  pool: 5
  username: root
  password:  Your Password (If you have)
  host: localhost


production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: DBName_production
  pool: 5
  username: root
  password: Your Password (If you have)
  host: localhost



After editing the database.yml file, go to the root of the Rails application via command-line


--->  rake db:create

This command will create the database or DBName_development in MySQL.



The following command can be used to your import SQL file (.sql) into DBName_development:



mysql -u root -p app_development < path_to_.sql/filename.sql
If SQL file is in another directory, for example, you can use ~/Desktop/filename.sql

A complete migration can be applied to the development database from the command line (inside your application's RAILS_ROOT directory):  rake db:migrate

1 comment: