MariaDB + Ruby on Rails

Today we completed the Ruby on Rails official getting started guide blog example to demonstrate CRUD using Maria DB instead of the default sqlite3.

It ran smoothly and gave me the ability to use phpmyadmin to poke around my database. Some issues encountered were that, despite declaring relationships between tables on the model level, by default the database does not show any cascading or auto-delete.  It may well be something that was beyond the scope of a quick start tutorial, or the functionality may not exist at all.

Switching from Sqlite to MariaDB involved two steps:

In the Gemfile, comment out gem ‘sqlite3’ and add a line gem ‘mysql2’

# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
gem 'mysql2'

In config/database.yml comment out the existing database connections and add this block (replacing it with your MariaDB credentials).

  adapter: mysql2
  encoding: utf8
  database: yourDatabaseName
  pool: 5
  username: yourDatabaseUsername
  password: yourDatabasePassword

Of course this is only working in the dev environment but you’d only need to define it for production in the same file by replacing development: with production: