---
title: "Rails 5 officially supports MariaDB"
description: "Rails 5 officially supports MariaDB"
canonical_url: "https://www.bigbinary.com/blog/rails-5-official-supports-mariadb"
markdown_url: "https://www.bigbinary.com/blog/rails-5-official-supports-mariadb.md"
---

# Rails 5 officially supports MariaDB

Rails 5 officially supports MariaDB

- Author: Vipul
- Published: April 21, 2016
- Categories: Rails 5, Rails

[MariaDB](https://mariadb.org/) 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](https://www.theguardian.com/technology/2009/dec/14/monty-widenius-oracle-protest)
of
[MySQL](http://www.infoworld.com/article/2630216/database/many-open-sourcers-back-an-oracle-takeover-of-mysql.html)
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](https://en.wikipedia.org/wiki/MariaDB?oldformat=true) .

Some of you might be wondering what advantages MariaDB offers over MySQL.Here is
an article which lists
[10 reasons](https://seravo.fi/2015/10-reasons-to-migrate-to-mariadb-if-still-using-mysql)
to migrate to MariaDB from MySQL.

MariaDB is bundled as default on systems like
[Redhat's RHEL 7+](http://www.itwire.com/business-it-news/open-source/60292-red-hat-ditches-mysql-switches-to-mariadb),
[Archlinux](https://www.archlinux.org/news/mariadb-replaces-mysql-in-repositories/),
[Slackware](http://www.slackware.com/index.html) and
[OpenBSD](http://marc.info/?l=openbsd-ports-cvs&m=141063182731679&w=2).

Some of the users of MariaDB are Google, Mozilla, Facebook and
[Wikipedia](http://blog.wikimedia.org/2013/04/22/wikipedia-adopts-mariadb/).
Later we found out that [Basecamp](https://basecamp.com/) has
[already been using MariaDB](https://github.com/rails/rails/pull/24454#issuecomment-206994634)
for a while.

## Active Record support for MariaDB

Recently, [Ian Gilfillan](https://github.com/iangilfillan) from MariaDB
Foundation sent a [Pull Request](https://github.com/rails/rails/pull/24454) to
include MariaDB as part Rails Documentation.

Accepting that pull request means Rails is
[committing to](https://github.com/rails/rails/pull/24522) supporting MariaDB
along with MySQL, PostgreSQL and SQLite.

The tests revealed an [issue](https://travis-ci.org/rails/rails/jobs/122573447)
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.

```ruby
time = ::Time.utc(2000, 1, 1, 12, 30, 0, 999999)
Task.create!(start: time)
Task.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.

```sql
 mysql> desc tasks;
+--------+---------+------+-----+---------+----------------+
| Field  | Type    | Null | Key | Default | Extra          |
+--------+---------+------+-----+---------+----------------+
| id     | int(11) | NO   | PRI | NULL    | auto_increment |
| start  | time    | YES  |     | NULL    |                |
+--------+---------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
```

In the above case column `start` is of type `time`.

Let's insert a record in `tasks` table.

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

Now let's query the table.

```sql
mysql> SELECT  `tasks`.* FROM `tasks` WHERE `tasks`.`start` = '2000-01-01 12:30:00' LIMIT 1;
Empty 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.

```sql
mysql> SELECT  `tasks`.* FROM `tasks` WHERE `tasks`.`start` = '12:30:00' LIMIT 1;
+----+----------+
| id | start    |
+----+----------+
|  1 | 12:30:00 |
+----+----------+
1 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](https://github.com/rails/rails/pull/24542), to take care of this
behavior from Rails side, was landed. MariaDB is itself,
[working](https://jira.mariadb.org/browse/MDEV-9541) on supporting this behavior
now.

## Summary

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

## Links

- [Human page](https://www.bigbinary.com/blog/rails-5-official-supports-mariadb)
