Create your first rails 3 application with mysql

Published on September 06, 2010 by Toran Billups

First install mysql from the command line

sudo apt-get install mysql-server libmysqlclient15-dev
gem install mysql
gem install mysql2

Now that mysql is installed you can create your first rails app like so

rails new blog -d mysql

After you get the app created, cd into the directory that gets generated. Next generate a simple post object with the following command

rails generate scaffold Post title:string body:text

Once this object is created you will need to create the database

rake db:create
rake db:migrate

The last thing to do is fire up the default web server that ships with rails and make sure everything is setup correctly.

rails server

To verify open your browser and type localhost:3000/posts and see if you can create a new object. If so you have a working rails 3 application with a mysql database!