Skip to content

Instantly share code, notes, and snippets.

@sdogruyol
Last active December 16, 2015 18:19
Show Gist options
  • Save sdogruyol/5476462 to your computer and use it in GitHub Desktop.
Save sdogruyol/5476462 to your computer and use it in GitHub Desktop.
Rails 3.2 Connection To Existing Mysql DB

Install Active Record Mysql Bindings

gem install activerecord-mysql2-adapter

Add mysql2 to your .Gemfile

gem 'mysql2'

Configure your DB Settings in config/database.yml

development:
    adapter: mysql2
    encoding: utf8
    database: mysql_db_name
    pool: 5
    username: root
    password: root_password
    socket: /tmp/mysql.sock

Dump the db structure

rake db:schema:dump

Create a migration file for initial db state in migrate/create_database.rb

  class CreateDatabase < ActiveRecord::Migration
    def self.up
      # Insert your db schema here
    end

  end

Create a model corresponding to your table name if your table names are not Rails Convention use

set_table_name 'your_table_name' 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment