Rails 5 officially supports MariaDB


By Vipul

on April 21, 2016

This blog is part of our  Rails 5 series.

MariaDB is an open source fork of the MySQL database and it acts as a drop-in replacement for MySQL.

After the Oracle's take over of MySQL there was some confusion about the future of MySQL. To remove any ambiguity about whether in future MySQL will remain free or not MariaDB was started .

Some of you might be wondering what advantages MariaDB offers over MySQL.Here is an article which lists 10 reasons to migrate to MariaDB from MySQL.

MariaDB is bundled as default on systems like Redhat's RHEL 7+, Archlinux, Slackware and OpenBSD.

Some of the users of MariaDB are Google, Mozilla, Facebook and Wikipedia. Later we found out that Basecamp has already been using MariaDB for a while.

Active Record support for MariaDB

Recently, Ian Gilfillan from MariaDB Foundation sent a Pull Request to include MariaDB as part Rails Documentation.

Accepting that pull request means Rails is committing to supporting MariaDB along with MySQL, PostgreSQL and SQLite.

The tests revealed an issue related to micro-precision support on time column.

If a column has time field and if we search on that column then the search was failing for MariaDB.

1time = ::Time.utc(2000, 1, 1, 12, 30, 0, 999999)
2Task.create!(start: time)
3Task.find_by(start: time) # => nil

In the above case we created a record. However query yielded no record.

Now let's see why the query did not work for MariaDB.

MariaDB vs MySQL time column difference

First let's examine the tasks table.

1 mysql> desc tasks;
3| Field  | Type    | Null | Key | Default | Extra          |
5| id     | int(11) | NO   | PRI | NULL    | auto_increment |
6| start  | time    | YES  |     | NULL    |                |
82 rows in set (0.00 sec)

In the above case column start is of type time.

Let's insert a record in tasks table.

1mysql> INSERT INTO `tasks` (`start`) VALUES ('2000-01-01 12:30:00');

Now let's query the table.

1mysql> SELECT  `tasks`.* FROM `tasks` WHERE `tasks`.`start` = '2000-01-01 12:30:00' LIMIT 1;
2Empty set (0.00 sec)

In the above case query is passing date part(2000-01-01) along with the time part(12:30:00) for column start and we did not get any result.

Now let's query again but this time we will pass only the time part to the start column.

1mysql> SELECT  `tasks`.* FROM `tasks` WHERE `tasks`.`start` = '12:30:00' LIMIT 1;
3| id | start    |
5|  1 | 12:30:00 |
71 row in set (0.00 sec)

So in the query if we pass 2000-01-01 12:30:00 to a column which is of type time then MariaDB fails.

Passing 2000-01-01 12:30:00 to MySQL, PostgreSQL and SQLite will work fine. That's because the adapters for those databases will drop the date part if date is passed in the query string.

For MariaDB similar action was needed and soon enough a Pull Request, to take care of this behavior from Rails side, was landed. MariaDB is itself, working on supporting this behavior now.


In summary Rails 5 officially supports MariaDB and MariaDB can now safely be used as an alternative to MySQL for Ruby on Rails Applications.

Stay up to date with our blogs. Sign up for our newsletter.

We write about Ruby on Rails, ReactJS, React Native, remote work,open source, engineering & design.