If you want to pass specific options like the table type and the charset to use when creating tabled though Rails migrations, pass an options parameter to the create_table method:

create_table :my_table, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8', :force => true do |t|
t.column :column1, :string
t.column :column2, :string

When you install a Rails application you need to initialize the DB tables where the data will be stored.

First, you need to create the database and give the correct privileges to a user to access the application. With mysql you will do the following:

  1. mysql -u root
  2. mysql> create database my_database;
  3. mysql> grant all privileges on my_database.* to my_user@localhost identified by ‘my_password’;
  4. mysql> flush privileges;

Then set this parameters in the rails application

  1. Edit the database.yml file in your application config folder
  2. You can configure three different environments there: development, test and production. Change the values for your environment:
    1. adapter: mysql
    2. database: my_database
    3. username: my_user
    4. password: my_password
    5. host: localhost
    6. socket should be set to the value specified  in the mysql configuration file. In Ubuntu this file is in /etc/mysql/my.cnf. In the [mysqld] section look for value of the socket variable, which in my system is /var/run/mysqld/mysqld.sock

Once your are done with the set up, creating the appropriate tables is damn easy with Rails migrations:

  1. cd into your Rails application folder
  2. Run ‘rake db:schema:load’
  3. You may also want to run ‘rake db:migrate’ in case you don’t have the latest version of the schema.rb file which sometimes  happens because developers forget to commit the changes.

You are done!

Note: In order to allow Rails to connect to the mysql database I had to enable the old password scheme in the mysql configuration file (/etc/mysql/my.cnf):

 old_passwords   = 1